# 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