I want to test web-application with the use of Pytest and Selenium. I want to capture screenshots only when a test method fails. I have the following fixture:
def driver_init(request): # set up driver def close_driver(): driver.quit() request.cls.driver = driver request.addfinalizer(close_driver) yield driver if request.node.rep_call.failed: try: allure.attach(driver.get_screenshot_as_png(), name=request.function.__name__, attachment_type=AttachmentType.PNG) except: pass
However when I run this code and the test method fails I receive a following error:
AttributeError: ‘Class’ object has no attribute ‘rep_call’.
What am I doing wrong?
Source: Python Questions