py.测试xdist捕获每个进程的所有输出

2024-06-16 08:59:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用pytest xdist进行测试。我在3个进程中运行测试,但是我的测试(和teardown)有stderr输出并希望捕获它。如果我使用:

def pytest_runtest_makereport(item, call):
    captured_stderr = item.outerr[1]
    if captured_stderr:
        with open("captured_" + str(os.getpid()), "a") as f:
            f.write(captured_stderr)

然后在捕获的文件中有一个输出,但是我希望它也有pytest诊断消息(因为我想稍后了解这个输出属于什么测试),比如[gw0] PASSED file:line test_something。如何将控制台输出保存到文件,但按每个进程拆分它?在


Tags: 文件if进程pytestdefwithstderrcall