Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pytest';s capsys.disabled()未按预期工作_Python_Pytest - Fatal编程技术网

Python Pytest';s capsys.disabled()未按预期工作

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__ == "_

我正在使用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__ == "__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()
没有影响吗

更新

此问题似乎与此问题中描述的相同: