pytest + xdist而不捕获输出? [英] pytest + xdist without capturing output?
问题描述
我正在使用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屋!