Hello,
I want to measure test coverage in my Django project.
I followed Django docs and installed the coverage
package. Then I executed from my project root:
coverage run --source="." manage.py test myapp
The test runner executes the tests, but the coverage report shows that no lines were executed. Example:
The only file with non-zero coverage, in red, is the project’s settings.py
file.
So far I’ve tried:
- running tests with
--source="myapp"
instead of--source="."
. Still zero coverage reported, but this time it logs a"No data collected"
error to the console. - wrapping
manage.py
withcoverage.Coverage()
as suggested in Adam Johnson’s blog. The command crashes withNoDataError("No data to report.")
. - running the entire test suite, instead of just 1 app
- Trying
pytest
andpytest-cov
– same result, sincepytest-cov
usescoverage
under the hood
I feel like I am missing some basic piece of config. My django project lives inside a Docker container and it’s structured like this:
project/
project_name/
settings.py
wsgi.py
...
app1/
app2/
module1/
module2/
I am running the comands from the project/
directory. All dependencies are installed globally.
Any suggestions? Thank you!