python
runtime_error
ai_generated
true
LogCaptureError: cannot use capsys and caplog at the same time
ID: python/pytest-capture-log-error
80%Fix Rate
81%Confidence
0Evidence
2024-11-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
Root Cause
在同一个测试函数中同时请求了 capsys 和 caplog fixture,pytest 不支持
generic中文
在同一个测试函数中同时请求了 capsys 和 caplog fixture,pytest 不支持
Workarounds
-
90% success
def test_foo(caplog): ... 使用 caplog.text 检查日志
-
85% success
def test_foo(capsys): ... 使用 capsys.readouterr()
Dead Ends
Common approaches that don't work:
-
50% fail
可能失去需要的功能
-
70% fail
capsys 捕获 stdout,不捕获日志