Python Pytest';s capsys.disabled()未按预期工作
我正在使用Pytest 3.1.3,它应该为中描述的Python Pytest';s capsys.disabled()未按预期工作,python,pytest,Python,Pytest,我正在使用Pytest 3.1.3,它应该为中描述的capsys夹具禁用disabled()方法。我尝试在以下简化测试中使用它: import pytest def test_capsys(capsys): with capsys.disabled(): print("foo") print("bar") out, err = capsys.readouterr() assert out == "bar\n" if __name__ == "_
capsys
夹具禁用disabled()
方法。我尝试在以下简化测试中使用它:
import pytest
def test_capsys(capsys):
with capsys.disabled():
print("foo")
print("bar")
out, err = capsys.readouterr()
assert out == "bar\n"
if __name__ == "__main__":
pytest.main([__file__])
然而,我的断言显然是不正确的:
=================================== FAILURES ===================================
_________________________________ test_capsys __________________________________
capsys = <_pytest.capture.CaptureFixture object at 0x102741ef0>
def test_capsys(capsys):
with capsys.disabled():
print("foo")
print("bar")
out, err = capsys.readouterr()
> assert out == "bar\n"
E AssertionError: assert '' == 'bar\n'
E + bar
try_capsys.py:8: AssertionError
----------------------------- Captured stdout call -----------------------------
bar
=========================== 1 failed in 0.03 seconds ===========================
==================================================================失败===================================
_________________________________测试卡普瑟斯__________________________________
capsys=
def测试_capsys(capsys):
禁用capsys.disabled()时:
打印(“foo”)
打印(“条”)
out,err=capsys.readouterr()
>断言输出==“条\n”
E断言错误:断言“”='bar\n'
E+巴
请尝试_capsys.py:8:AssertionError
-----------------------------捕获的stdout调用-----------------------------
酒吧
=====================================1在0.03秒内失败===========================
注意,如果我用块注释掉,测试通过。我不明白:带
的块不应该对capsys.readouterr()
没有影响吗
更新
此问题似乎与此问题中描述的相同: