Skip to content

Instantly share code, notes, and snippets.

@jaforsgren
Created April 16, 2019 11:24
Show Gist options
  • Save jaforsgren/378505269717fc1d13d6c98ab5f277b3 to your computer and use it in GitHub Desktop.
Save jaforsgren/378505269717fc1d13d6c98ab5f277b3 to your computer and use it in GitHub Desktop.
pytest fixture report ion failiure
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
# set a report attribute for each phase of a call, which can
# be "setup", "call", "teardown"
setattr(item, "rep_" + rep.when, rep)
@pytest.fixture
def something(request):
yield
# request.node is an "item" because we use the default
# "function" scope
if request.node.rep_setup.failed:
print("setting up a test failed!", request.node.nodeid)
elif request.node.rep_setup.passed:
if request.node.rep_call.failed:
print(request.node.user_properties)
print("executing test failed uwu ", request.node.nodeid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment