【发布时间】:2019-08-17 11:33:47
【问题描述】:
这应该是一件简单的事情,但我无法弄清楚是什么导致了错误。
我正在关注pytest docs,了解如何将标准输出捕获到对象中,但出现以下错误:
capsys = <_pytest.capture.CaptureFixture object at 0x7f02a1e2f7f0>
def test_can_output_to_stdout(capsys):
print("hello")
> capture = capsys.readouterror()
E AttributeError: 'CaptureFixture' object has no attribute 'readouterror'
test_aaa.py:5: AttributeError
我使用的代码类似于:
import pytest
def test_can_output_to_stdout(capsys):
print("hello")
capture = capsys.readouterror()
assert "hello" in capture.out
我这样称呼测试:
py.test --capture=sys --capture=fd test_aaa.py
版本是:
pytest:
py.test --version
This is pytest version 4.6.5, imported from /usr/local/lib/python3.4/site-packages/pytest.p
Python:
python --version
Python 3.4.8
任何帮助将不胜感激。
【问题讨论】:
标签: python python-3.x pytest stdio