Reputation: 1245
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 ==============================================
Upvotes: 18
Views: 40077
Reputation: 53
You need all tests to start with test_
but also you need to tell Pytest exact which files to look for:
# pytest.ini
[pytest]
python_files = tests.py test_*.py
Upvotes: 4
Reputation: 1
For example, there is apples/apple.py
as shown below:
project
|-pytest.ini
└-apples
|-__init__.py
└-apple.py # Here
Then, there is apple(self)
in Apple
class in apples/apple.py
as shown below:
# "apples/apple.py"
import pytest
class Apple:
def apple(self):
assert True
Now, with this pytest.ini
below, apple(self)
cannot be run because by default, Pytest can run the files test_*.py
and *_test.py
, the classes prefixed with Test
and the functions prefixed with test
instead of apple.py
file, Apple
class and apple(self)
function according to python_files, python_classes and python_functions and by default, Pytest can run any folders like apples
:
# "pytest.ini"
[pytest]
So, with this pytest.ini
below, apple(self)
can be run:
# "pytest.ini"
[pytest]
python_files = apple.py
python_classes = Apple
python_functions = apple
In addition, by default, you can run all the tests in apples/test_1.py
, apples/oranges/test_2.py
, bananas/test_1.py
and banana/kiwis/test_2.py
as shown below because as I said above, by default, Pytest can run any folders like apples
, oranges
, bananas
and kiwis
. *My answer explains it:
project
|-pytest.ini
|-apples
| |-__init__.py
| |-test_1.py # Here
| └-oranges
| |-__init__.py
| └-test_2.py # Here
└-bananas
|-__init__.py
|-test_1.py # Here
└-kiwis
|-__init__.py
└-test_2.py Here
Upvotes: 0
Reputation: 1245
To determine why tests are not running, these steps are useful:
pytest.ini
file in the root directory.__init__.py
file in all directories/sub-directories of the project.Upvotes: 55
Reputation: 818
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):
...
Upvotes: 2