11

I want to make some unit tests, so I set up a list with values that all should be asserted true, just like this question. But I want it to run in PyCharm (With pressing Alt+Shift+F10)

If I just use the code from the answers, I just get No tests were found

Community
  • 1
  • 1
Ramzi Khahil
  • 4,932
  • 4
  • 35
  • 69

3 Answers3

24

You need to double check the settings for the tests run configuration:

settings

By default PyCharm will inspect files that start with test and that are subclasses of unittest.TestCase, however you can control the Pattern and the subclasses option.

Change Pattern according to your test file names, it accepts Python regular expression.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 5
    That filename started with "test*" pattern were really helped me. And it is case sensitive... – swdev Feb 08 '14 at 04:46
0

Note that PyCharm will inspect only classes that inherit from unittest.TestCase so you should write the tests inside a class inherited from unittest.TestCase

Mitzi
  • 2,652
  • 1
  • 20
  • 15
  • 1
    That's not true. PyCharm supports `py.test` which does not require any test classes to extend `unittest.TestCase` (`py.test` promises no APIs) – fatuhoku Sep 01 '13 at 17:44
0

PyCharm 2019.1+ and pytest

First, create a file named pytest.ini in order to set up custom configurations. For example, by default pytest will consider any file matching with test_*.py and *_test.py globs as a test module, so I encourage to have this file in order to define your custom file name patterns.

pytest.ini

[pytest]
python_files = test_*.py tests.py *_test.py

Now, open up the Run/Configuration window:

enter image description here

Add a new configuration, select Python tests and pytest:

enter image description here

In the following window you choose a name for your configuration, and you can also choose the target, but if you want pytest to use the pytest.ini file do not select Script path, APPLY, and OK.

enter image description here

Finally, run the test by clicking on the Play button.

enter image description here

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228