Run a specific unit test function inside PyCharm IDE 5.0.4

Viewed 11828

I am trying to use PyCharm for unit testing (with unittest), and am able to make it work: the test runner nicely shows the list of test cases and nested test functions.

However, once the tests have been discovered, I cannot find any way to (re)run a specific test function: the only button available will run the whole list of tests, and right clicking on a single test function doesn't show any meaningful action for this purpose.

enter image description here

As you can imagine, it can take a long time unnecessarily when the purpose is to debug a single test.

How to achieve this? It is possible in Visual Studio for example, and seems like a basic feature so I assume I must be missing something.

7 Answers

Under pycharm 2017.2.3:

the key step:

  1. change the default test runner(unittests) to (nosetests or py.test), both ok.
  2. then the IDE can run single test function now.
  3. follow the steps of the below screenshots.

1. change settings:

enter image description here

2. run single test function:

enter image description here

enter image description here

3. run all test functions:

enter image description here

enter image description here

In Pycharm 2018.1: restart, delete the existing run configrations - suddently right-click provides an option to run a single test. :-/

Please check whether you have the same test name repeated in two or more locations in the test fixture. I had the same problem and resolving the naming conflicts enabled me to right click on the test name and run it individually.

I had this problem with PyCharm 2018.3.

It seemed to be because I had a breakpoint in a strange place (at function declaration, instead of inside the function).

Clearing all the breakpoints seemed to restore the ability to debug individual tests

Related