Why does PyCharm not run pytest testing for my application?

I'm new to pytest and am trying to write testing modules for my application. My directory structure is:


I want to test the db.py module.

I configure pycharm to use pytest as my test runner ( I verified this). When I run the test_db.py in pycharm I get:

/Users/cbogdon/virtualenv/platinum-onboard/bin/python /Users/cbogdon/coding/platinum-onboard/broker/tests/test_db.py

Process finished with exit code 0

It's almost like pycharm is not executing the pytest. Even if I right click on the green arrow to the left of one of my testing functions a menu appears and shows I can click: "Run 'pytest for test_db.py::TestDBFunctions::test_valid_db'"

If I run it at the command line using:

python -m pytest --setup-show tests/test_db.py 

I  get the appropriate test output:

python -m pytest --setup-show tests/test_db.py 
========================================================== test session starts ===========================================================
platform darwin -- Python 3.6.1, pytest-4.1.1, py-1.7.0, pluggy-0.8.1
rootdir: /Users/cbogdon/coding/platinum-onboard/broker, inifile:
collected 4 items  

=================================================== 1 failed, 3 passed in 0.08 seconds ==================================================

Is there something special I need to do in PyCharm?

Sorry for the newbie question, but I just can't figure this out one bit!   I almost want to say maybe I hit an issue, but I can't be sure.    Any ideas on how to help?


I invalidated the cache and restarte to see if that made a difference and it diddn't.




Comment actions Permalink

Hi Chris,

It seems that PyCharm run the normal configuration instead of a test. Please try to manually create a pytest configuration in **Run > Edit configurations > "+" button > Python tests > pytest**

See screenshot: http://bit.ly/2HGMArX

Explicitly specify the path to your script and run it.

Comment actions Permalink

So that was in fact the issue.   It wasn’t clear because all the documentation didn’t specify that I manually had to create that profile for each test.   But now that I know, hopefully it will be easier in the future.

Comment actions Permalink

Well, you don't always have to create it manually, it should be created automatically when you click the green arrow. But in your case it doesn't do that for some reason.

Anyway, creating configurations manually is preferred as it gives you more control over what you are doing.

Comment actions Permalink

well, it seems that Chris's problem is also my problem. It doesn't seem to matter what caches I clear, what process i use in installation and reinstallation of pycharm, what tooling setups I use, it simply refuses to recognise Pytest in any useful way.

Comment actions Permalink

Hi Michael,

Could you clarify if you have this problem even with a new script with some simple pytest?
Make sure you don't have any run configurations for that script before running it as a pytest. Otherwise, PyCharm will pick that up.


Please sign in to leave a comment.