pytest:如何仅对特定的测试代码行禁用stdout捕获

我知道可以通过使用-s / --capture=no开关来禁用pytest中的stdout和stderr捕获。另外,在测试特定功能时,可以使用capsys固定装置及其禁用方法:

def test_disabling_capturing(capsys):
    print("this output is captured")
    with capsys.disabled():
        foo():
    print("this output is also captured")

def foo():
    print("output not captured,going directly to sys.stdout")

但是,整个功能foo()的捕获被禁用。如果我只想对foo()的特定行禁用捕获(出于测试运行时输出流的可读性)怎么办?

我知道可以将capsys固定装置作为参数传递给被测试的函数(也可以通过任何嵌套函数),但是我想知道是否有更好的方法可以不修改功能。

xiaokuku 回答:pytest:如何仅对特定的测试代码行禁用stdout捕获

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3135958.html

大家都在问