I am running the following through a Makefile
:
NPROCS:=$(shell /usr/bin/nproc)
.PHONY: coverage-app
coverage-app:
coverage erase --rcfile=./.coveragerc-app
coverage run --parallel-mode --rcfile=./.coveragerc-app manage.py test -v 3 --parallel=$(NPROCS) app
coverage combine --rcfile=./.coveragerc-app
coverage report -m --rcfile=./.coveragerc-app
If I set NPROCS
to 1, I get the expected 100% test coverage of all files within app
. However, if NPROCS
is greater than 1, I get lots of missing lines in my report.
What am I doing wrong?
My .coveragerc-app
is as follows:
# Control coverage.py
[run]
branch = True
omit = */__init__*
*/test*.py
*/migrations/*
*/urls.py
app/admin.py
app/apps.py
source = app
parallel = true
[report]
precision = 1
show_missing = True
ignore_errors = True
exclude_lines =
pragma: no cover
raise NotImplementedError
except ImportError
def __repr__
if self\.logger\.debug
if __name__ == .__main__.:
You miss a few steps, from Measuring sub-processes:
COVERAGE_PROCESS_START=./.coveragerc-app coverage run
--parallel-mode --concurrency=multiprocessing
--rcfile=./.coveragerc-app manage.py test -v 3 --parallel=$(NPROCS) app
import coverage
coverage.process_startup()
concurrency=multiprocessing
Took a read through the coverage documentation linked in answer above, perhaps it's been updated, as just doing the following seems to work for our Django project:
coverage run --concurrency=multiprocessing manage.py test app --parallel=3
coverage combine
coverage report
Per the documentation:
Coverage should be run in a single process to obtain accurate statistics.
Not an answer to this question but for those looking to optimize their project in this manner it may be helpful to know it isn't recommended by Django maintainers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With