Python unittest with (sub) process coverage reports
I use nose
"unittest" to run my tests and nose-cov
to enable coverage reports. They all work fine, but some of my tests require some code like multiprocessing.Process
. The docs nose-cov
indicate that it can do it multiprocessing
, but I'm not sure how to do it.
I just run tests by running nosetests
and using the following .coveragerc
:
[run]
branch = True
parallel = True
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
#if self\.debug
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
def __main__\(\):
omit =
mainserver/tests/*
EDIT:
I have set the switch parallel
to my .coveragerc file. I also tried adding sitecustomize.py
to my site directory:
import os
import coverage
os.environ['COVERAGE_PROCESS_START']='/sites/metrics_dev/.coveragerc'
coverage.process_startup()
I'm pretty sure it still doesn't work as expected because the "missing" report still shows lines that I know to work (they are output to the console) . I also tried adding an environment variable to the test case file as well as to the shell before running the test cases. I also tried to explicitly call the same functions in the function I called multiprocessing.Process
to start a new process.
source to share
First, the config option you want parallel
, not parallel-mode
. Second, you probably need to follow the directions in the section Measuring subprocesses in the coverage.py docs.
source to share