首页 > 其他分享 >pytest结合allure 失败截图

pytest结合allure 失败截图

时间:2022-10-06 07:55:06浏览次数:56  
标签:截图 allure get rep driver pytest

# conftest.py

driver = None

@pytest.fixture()
def driver():
    global driver
    driver = webdriver.Chrome()
    driver.get("http://www.baidu.com")
    yield driver

@pytest.hookimpl(tryfirst=True,hookwrapper=True)
def pytest_runtest_makereport(item,call):
    outcome = yield
    rep=outcome.get_result()
    if rep.when=="call" and rep.failed:
        if driver:
            allure.attach(body=driver.get_screenshot_as_png(),name="失败用例截图",attachment_type=allure.attachment_type.PNG)

标签:截图,allure,get,rep,driver,pytest
From: https://www.cnblogs.com/py-zhq/p/16756962.html

相关文章