【问题标题】:How to run coverage report with parallel pytest using xdist and django_coverage_plugin如何使用 xdist 和 django_coverage_plugin 通过并行 pytest 运行覆盖率报告
【发布时间】:2023-02-18 13:25:15
【问题描述】:

使用以下设置,计算出的覆盖率比我使用没有并行化的单线程要小。 Coverage 在项目根目录中只创建了 1 个覆盖文件,我认为这是问题所在。

我无法确定我做错了什么,报告的覆盖率低于我只是运行coverage -m pytest(在单个线程上)。测试本身并行运行就好了。

任何人都可以识别我的错误吗?我想知道是否缺少环境变量。我从项目根目录运行命令,其中包含.coveragercsitecustomize.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


【解决方案1】:

https://github.com/nedbat/coveragepy/issues/1341 提供了一些上下文(以及可能的解决方案),特别是这条评论:https://github.com/nedbat/coveragepy/issues/1341#issuecomment-1302863172

我试图添加 coverage-enable-subprocess 包,但没有成功。

我切换到使用pytest-cov并在使用pytest-xdist时获得了覆盖率报告)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 2019-03-16
    • 2015-05-16
    • 2021-06-22
    • 2021-09-27
    • 2013-10-06
    相关资源
    最近更新 更多