pytest生成报告(使用pytest)后如何执行代码?

use*_*999 3 pytest

因此,我尝试在 pytest 完成执行后自动将 html 报告(pytest 创建的)SFTP 到服务器。这是否存在于 pytest 中还是我必须创建一个包装器?

我知道有“设置”和“拆卸”方法,并且存在一个拆卸方法,您可以在所有测试运行后执行该方法,但这发生在生成报告之前(不是我想要的!)。

San*_*nju 6

您可以在pytest_unconfigure挂钩中处理此问题。如果您使用pytest-html生成测试报告,您可以执行类似的操作来访问报告的路径

# in conftest.py
def pytest_unconfigure(config):
    html_report = config._html.logfile   # provides full path of generated html report
    # or
    html_report = config.option.htmlpath  # provides the value passed with --html command line option
    # your code to upload to sftp goes here
Run Code Online (Sandbox Code Playgroud)