python
runtime_error
ai_generated
true
AttributeError: 'CaptureFixture' 对象没有属性 'readouterr'
AttributeError: 'CaptureFixture' object has no attribute 'readouterr'
ID: python/pytest-capture-no-output
80%修复率
88%置信度
0证据数
2024-11-09首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
在新版 pytest 中,`capsys` 返回 `CaptureFixture` 对象,读取输出的方法为 `readouterr()`。拼写错误(如 `read_outerr`)或误用 `capfd` 会导致此错误。
English
In newer pytest versions, `capsys` returns a `CaptureFixture` object and the method to read output is `readouterr()`. In some versions a typo like `read_outerr` or using `capfd` incorrectly causes this.
解决方案
-
97% 成功率
Use the correct method: def test_out(capsys): print('hi') captured = capsys.readouterr() assert captured.out == 'hi\n'
无效尝试
常见但无效的做法:
-
80% 失败
These methods don't exist on CaptureFixture.
-
70% 失败
Same API surface; typo persists.