我nose
用来运行我的“单元测试”测试并且必须nose-cov
包含覆盖率报告。这些都可以正常工作,但我的部分测试需要将一些代码作为multiprocessing.Process
. 文档说明nose-cov
它可以做到multiprocessing
,但我不确定如何让它发挥作用。
我只是通过运行nosetests
和使用以下内容来运行测试.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/*
编辑:
我在“.coveragerc”文件中修复了parallel
开关。我也尝试sitecustomize.py
在我的站点包目录中添加一个这样的:
import os
import coverage
os.environ['COVERAGE_PROCESS_START']='/sites/metrics_dev/.coveragerc'
coverage.process_startup()
不过,我很确定它仍然无法正常工作,因为“丢失”报告仍然显示我知道正在运行的行(它们输出到控制台)。在运行测试用例之前,我还尝试在我的测试用例文件和 shell 中添加环境变量。我还尝试在被调用的函数中显式调用相同的东西multiprocessing.Process
来启动新进程。