Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pytest how to run tests / django

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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 as test*.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 an app_dir/tests.py file. Also, it is common to put tests under app_dir/tests/views.py, etc.

To find those tests, create a pytest.ini file in your project root and add an appropriate python_files line to it:

[pytest]
python_files = tests.py test_*.py *_tests.py
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading