为什么 pytest + xdist 不捕获输出? [英] Why does pytest + xdist not capture output?

查看:49
本文介绍了为什么 pytest + xdist 不捕获输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 pytest 和 pytest-xdist 进行并行测试运行.它似乎不支持 -s 选项,用于在测试运行时将标准输出传递到终端.有什么办法可以做到这一点吗?我意识到这可能会导致来自不同进程的输出在终端中混乱,但我对此没有意见.

I'm using pytest with pytest-xdist for parallel test running. It doesn't seem to honour the -s option for passing through the standard output to the terminal as the tests are run. Is there any way to make this happen? I realise this could cause the output from the different processes to be jumbled up in the terminal but I'm ok with that.

推荐答案

我找到了一种解决方法,尽管不是完整的解决方案.通过将 stdout 重定向到 stderr,可以显示打印语句的输出.这可以通过一行 Python 代码来完成:

I found a workaround, although not a full solution. By redirecting stdout to stderr, the output of print statements is displayed. This can be accomplished with a single line of Python code:

sys.stdout = sys.stderr

如果放在 conftest.py 中,则适用于所有测试.

If placed in conftest.py, it applies to all tests.

这篇关于为什么 pytest + xdist 不捕获输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆