pytest doesn't run any test
Question:
pytest doesn’t run any tests and it is not clear why. I tried to use –debug but didn’t get any valuable information. It is completely not clear how to debug this sort of issues with pytest. (Looks like some issue with pytest configuration / env variables / test names patterns?)
Example of test file:
import pytest
@pytest.mark.sanity
def test_me():
"""I'm a test."""
assert True
But pytest doesn’t run any test, why?
$ pytest
================================================== test session starts ===================================================
platform linux2 -- Python 2.7.12, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/qawizard/pytest-hell, inifile:
plugins: xdist-1.15.0, timeout-1.2.0
collected 1 item s
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Exit: Done! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================== no tests ran in 0.13 seconds ==============================================
Answers:
To determine why tests are not running, these steps are useful:
- Verify that all files with test cases start with ‘test_’ word.
- Verify that all test cases names also start with ‘test_’ word.
- Verify that you have created
pytest.ini
file in the root directory.
- Verify that you have
__init__.py
file in all directories/sub-directories of the project.
You need all tests to start with test_
but also you need to tell Pytest exact which files to look for:
# pytest.ini
[pytest]
DJANGO_SETTIONS_MODULE = myproject.settings
python_files = tests.py test_*.py
For me my class name didn’t start with test.
my code was
class MainTest:
...
def test_properties(self):
...
This wont work because pytest will assume this class shouldn’t be included.
Changing to this did it for me.
class TestMain:
...
def test_properties(self):
...
pytest doesn’t run any tests and it is not clear why. I tried to use –debug but didn’t get any valuable information. It is completely not clear how to debug this sort of issues with pytest. (Looks like some issue with pytest configuration / env variables / test names patterns?)
Example of test file:
import pytest
@pytest.mark.sanity
def test_me():
"""I'm a test."""
assert True
But pytest doesn’t run any test, why?
$ pytest
================================================== test session starts ===================================================
platform linux2 -- Python 2.7.12, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/qawizard/pytest-hell, inifile:
plugins: xdist-1.15.0, timeout-1.2.0
collected 1 item s
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Exit: Done! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================== no tests ran in 0.13 seconds ==============================================
To determine why tests are not running, these steps are useful:
- Verify that all files with test cases start with ‘test_’ word.
- Verify that all test cases names also start with ‘test_’ word.
- Verify that you have created
pytest.ini
file in the root directory. - Verify that you have
__init__.py
file in all directories/sub-directories of the project.
You need all tests to start with test_
but also you need to tell Pytest exact which files to look for:
# pytest.ini
[pytest]
DJANGO_SETTIONS_MODULE = myproject.settings
python_files = tests.py test_*.py
For me my class name didn’t start with test.
my code was
class MainTest:
...
def test_properties(self):
...
This wont work because pytest will assume this class shouldn’t be included.
Changing to this did it for me.
class TestMain:
...
def test_properties(self):
...