python
config_error
ai_generated
true
CoverageWarning: 未测量到任何上下文 warnings.warn("No contexts were measured")
CoverageWarning: No contexts were measured warnings.warn("No contexts were measured")
ID: python/pytest-cov-context-not-configured
80%修复率
80%置信度
0证据数
2024-08-27首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 5.x | active | — | — | — |
根因分析
传入了 `--cov-context=test`,但 coverage 配置未启用动态上下文,或 coverage 版本不支持所请求的上下文模式。
English
`--cov-context=test` was passed but the coverage config does not enable dynamic contexts, or the coverage version does not support the requested context mode.
解决方案
-
90% 成功率
Enable dynamic contexts in coverage config: # pyproject.toml [tool.coverage.run] dynamic_context = "test_function" # then run: pytest --cov=myapp --cov-context=test
-
85% 成功率
Or set the env var before running: COVERAGE_DYNAMIC_CONTEXT=test_function pytest --cov=myapp --cov-context=test
无效尝试
常见但无效的做法:
-
85% 失败
Only affects the failure threshold; contexts still not measured.
-
60% 失败
Hides the warning but loses per-test coverage reporting that was the goal.