首页 > 解决方案 > OSError:pytest:在捕获输出时从标准输入读取!考虑使用`-s`

问题描述

在使用 pytest 运行特定的单元测试时,它偶尔会因此错误而失败(在标题中提到),并且从堆栈跟踪中它发生在行上

    self = <_pytest.capture.DontReadFromInput object at 0x0000024AD00E7668>
args = ()

    def read(self, *args):
        raise IOError(
>           "pytest: reading from stdin while output is captured!  Consider using `-s`."
        )
E       OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.

错误位置代码:</p>

def setUp(self):
    desired_caps = {}
    id = input("please input your number:&quot;)

标签: pythonpytest

解决方案


尝试将函数提取到一个单独的文件中,在文件中调用它们并使用 -s 标志运行 pytest,例如 pytest FILENAME -s


推荐阅读