2017-07-27 71 views
1

所以我試圖自動SFTP一個HTML報告(pytest創建)到Pytest完成執行後的服務器。這是pytest存在還是我必須創建一個包裝?如何在pytest生成報告(使用pytest)後執行代碼?

我知道有「setup」和「teardown」方法,並且存在可以在所有測試運行後執行的拆卸方法,但是在報告生成之前會發生這種情況(不是我想要的!)。

回答

2

您可以在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