pytestrongessionfinish函数在所有测试结束时运行。如果检查worker input属性,它将在所有其他进程完成测试后在主线程中运行
我写了几个测试,在所有测试运行完成后,我想调用一个方法来发送带有测试报告的电子邮件。当使用pytest和xdist并行运行时,如何只调用一次此方法?
def pytest_sessionfinish(session, exitstatus):
"""Insert teardown that you want to occur only once here"""
if not hasattr(session.config, "workerinput"):
pass # whatever you want to do here
来源:https://github.com/pytest-dev/pytest-xdist/issues/271#issuecomment-826396320