Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a specific unit test function inside PyCharm IDE 5.0.4

Tags:

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.

like image 480
Erwin Mayer Avatar asked Mar 18 '16 08:03

Erwin Mayer


People also ask

How do I run a unit test in PyCharm?

PyCharm makes it easy to select just one test to run. In fact, there are several ways to do it: With the cursor anywhere in the test you want to focus on, right-click and choose to run that in the test runner. Right-click on the test in the test tool listing and choose to run it.


Video Answer


1 Answers

Check the default test framework of the project...

You're perhaps used to 'unittest' being the default. Its enables me to put the cursor on the test definition and hit "SHIFT-CTRL-R" to run that one test.

The default seems to have changed to 'py.test' which has different behaviour and keyboard shortcuts. I'm on OSX so ymmv.

On Linux:

File -> Settings -> Tools -> Python Integrated Tools -> Testing / "Default Test Runner"

On OSX:

Preferences -> Tools -> Python Integrated Tools -> "Default test runner:"

enter image description here

like image 66
John Mee Avatar answered Sep 23 '22 13:09

John Mee