I'm trying to use pytest for the 1st time in my new created app but i'm facing problems with running it. I still receive 'no tests ran in...' message.
My project name is PROJECT, then is my app called diet_app
and file tests.py
inside the app folder.
How to run tests?
I tried with:
pytest
pytest tests
pytest diet_app
To be more precise - to install PyTest I used:
pip install pytest
pip install pytest-django
I'm working in PyCharm
CodePudding user response:
pytest-django doesn't actually find tests in a file called tests.py
out of the box. If you want to keep using a file called tests.py
you'll need to add a pytest.ini
file in your top-level directory:
My tests are not being found. Why?
By default, pytest looks for tests in files named
test_*.py
(note that this is not the same astest*.py
) and*_test.py
. If you have your tests in files with other names, they will not be collected. Note that Django’s startapp manage command creates anapp_dir/tests.py
file. Also, it is common to put tests underapp_dir/tests/views.py
, etc.To find those tests, create a
pytest.ini
file in your project root and add an appropriatepython_files
line to it:[pytest] python_files = tests.py test_*.py *_tests.py