[英]Pytest print to stdout despite of output capturing
I am aware that PyTest captures the output (stdout, stderr, ...) for the tests it executes , and that is an awesome feature I want to keep.我知道 PyTest 为其执行的测试捕获输出(stdout、stderr、...),这是我想要保留的一个很棒的功能。 However, there is some content that I wish to print to the console immediately from my within
conftest.py
file, as general information to the person watching the test execution from their terminal.但是,我希望立即从我的
conftest.py
文件中将一些内容打印到控制台,作为从终端观看测试执行的人的一般信息。 Using a print statement there does not work, as the output of the conftest.py
file seems to also be captured, and is only shown if an error happens while executing that file.使用打印语句不起作用,因为
conftest.py
文件的输出似乎也被捕获,并且仅在执行该文件时发生错误时才显示。
Is there a way for me to explicitly bypass this "PyTest output capturing" for a single print statement?有没有办法让我为单个打印语句显式绕过这个“PyTest 输出捕获”?
On Unix you could open the controlling terminal and print to it directly:在 Unix 上,您可以打开控制终端并直接打印到它:
import os
termfd = open(os.ctermid(), "w")
termfd.write("hello")
termfd.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.