【发布时间】:2023-02-18 13:25:15
【问题描述】:
使用以下设置,计算出的覆盖率比我使用没有并行化的单线程要小。 Coverage 在项目根目录中只创建了 1 个覆盖文件,我认为这是问题所在。
我无法确定我做错了什么,报告的覆盖率低于我只是运行coverage -m pytest(在单个线程上)。测试本身并行运行就好了。
任何人都可以识别我的错误吗?我想知道是否缺少环境变量。我从项目根目录运行命令,其中包含.coveragerc 和sitecustomize.py。
coverage erase && COVERAGE_PROCESS_START=./.coveragerc coverage run --concurrency=multiprocessing --parallel-mode -m pytest -n 8 && coverage combine && coverage report
站点自定义.py
import coverage
coverage.process_startup()
.coveragerc
[run]
include =
lettergun/*
omit =
*migrations*
*tests*
*.html
plugins = django_coverage_plugin
parallel = True
concurrency = multiprocessing
branch = True
测试文件
[pytest]
addopts = --ds=config.settings.test --reuse-db -n 8
python_files = test_*.py
norecursedirs = node_modules
DJANGO_SETTINGS_MODULE = config.settings.test
【问题讨论】:
-
嘿@John,您找到解决方案了吗?
-
我没有。我在生成覆盖率报告时缓慢地运行测试,在我不关心覆盖率报告时并行地运行测试。
标签: python pytest code-coverage coverage.py pytest-django