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.

+3


source to share


2 answers


Another thing to consider is if you see more than one coverage file when starting coverage. Perhaps it's just a matter of uniting them.



+1


source


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.



0


source







All Articles