python
runtime_error
ai_generated
true
日志捕获错误:不能同时使用 capsys 和 caplog
LogCaptureError: cannot use capsys and caplog at the same time
ID: python/pytest-capture-log-error
80%修复率
81%置信度
0证据数
2024-11-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
根因分析
在同一个测试函数中同时请求了 capsys 和 caplog fixture,pytest 不支持
English
在同一个测试函数中同时请求了 capsys 和 caplog fixture,pytest 不支持
解决方案
-
90% 成功率
def test_foo(caplog): ... 使用 caplog.text 检查日志
-
85% 成功率
def test_foo(capsys): ... 使用 capsys.readouterr()
无效尝试
常见但无效的做法:
-
50% 失败
可能失去需要的功能
-
70% 失败
capsys 捕获 stdout,不捕获日志