Search code examples
python-3.xpycharm

Getting empty test suite when running with pytest from pycharm


I'm having issues with running pytest tests from inside PyCharm

I have a file x_tests.py inside a folder called agents_automation_2 in C:\Temp, the content of the file is

import pytest
def test_mytest():
    assert  False

When I run I get the following output

C:\Python36-32\python.exe "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pycharm\_jb_pytest_runner.py" --path C:/Temp/agents_automation_2
Launching py.test with arguments C:/Temp/agents_automation_2 in C:\Temp\agents_automation_2
============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-3.4.2, py-1.5.2, pluggy-0.6.0
rootdir: C:\Temp\agents_automation_2, inifile:
plugins: xdist-1.22.0, forked-0.2
collected 0 items
======================== no tests ran in 0.01 seconds =========================

However, when I run from a regular windows command line inside the folder the test runs OK

Any idea of what might be the issue ?

Thanks !!!


Solution

  • The name of your test file does not conform to a default pytest discovery rules. If you change x_tests.py to x_test.py it run the test and fails as expected. Take a look at this page for more info on pytest discovery rules.