python - 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:")
解决方案
尝试将函数提取到一个单独的文件中,在文件中调用它们并使用 -s 标志运行 pytest,例如 pytest FILENAME -s
推荐阅读
- java - 获取设备的位置,无论应用程序处于什么状态始终从我的公司应用程序中检测位置
- python - 混淆矩阵呈现一些空单元格
- regex - 如何在忽略第一场比赛的同时从一个点grep到另一个点?
- javascript - 如何从另一个组件更改组件状态?
- javascript - 这个参数化查询如何防止 SQL 注入?
- html - 尽管使用简单,媒体查询仍不起作用
- npm - Vue-Cli3 和最近的 Node-Sass DoS 咨询:如何用 dart-sass 替换 node-sass?
- sql - 创建函数后我应该 COMMIT 吗?
- python - 检查字符串中的 id 是否存在于另一个列表中
- angular - 如何以角度获取和显示实时用户通知?