Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
583 B
2
Indexable
Never
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    rep = outcome.get_result()
    if "driver" in item.funcargs and "config" in item.funcargs and rep.when == 'call' and rep.failed:
        logging.debug("Saving test failure screenshot!")
        driver = item.funcargs['driver']
        config = item.funcargs['config']
        filename = f'debug_screenshot_{item.obj.__name__}_{datetime.today().strftime("%Y-%m-%d_%H:%M:%S")}.png'
        driver.save_screenshot(f'{os.path.join(config.files_dir, filename)}')
Leave a Comment