pytest结合allure 失败截图

# 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)

posted @ 2022-10-06 07:47  zhq9  阅读(63)  评论(0编辑  收藏  举报