python
runtime_error
ai_generated
true
PytestWarning: 检测到慢速测试:test_heavy_computation 耗时 5.23s
PytestWarning: Slow test detected: test_heavy_computation took 5.23s
ID: python/pytest-slow-test-warning
80%修复率
85%置信度
0证据数
2025-12-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
pytest-slow-test 插件或自定义钩子标记了超过时间阈值的测试。这是警告而非错误,但如果警告被视为错误,则会导致失败。
English
The pytest-slow-test plugin or a custom hook flags a test that exceeds a time threshold. This is a warning, not an error, but may be treated as an error if warnings are errors.
解决方案
-
95% 成功率
Use smaller datasets, mock heavy operations, or use caching.
-
90% 成功率
@pytest.mark.slow def test_heavy_computation(): ... Run with: pytest -m 'not slow' -
85% 成功率
@pytest.mark.slow_test_threshold(10) def test_heavy_computation(): ...
无效尝试
常见但无效的做法:
-
90% 失败
This reduces coverage and may remove important test cases.
-
80% 失败
This masks the performance issue and may allow very slow tests to persist.
-
70% 失败
If warnings are errors, the test suite still fails.