Is it possible exclude test directories from coverage.py reports? Is it possible exclude test directories from coverage.py reports? python python

Is it possible exclude test directories from coverage.py reports?


Create .coveragerc file in your project root folder, and include the following:

[run]omit = *tests*


Leaving this here in case if any Django developer needs a .coveragerc for his project.

[run]source = .omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py[report]omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py

Create a file named .coveragerc on your projects root directory, paste the above code and then just run the command:

coverage run manage.py test

In addition, if you want the tests to execute faster run this command instead.

coverage run manage.py test --keepdb --parallel

This will preserve the test DB and will run the tests in parallel.