Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save weissjeffm/fcd7e5b311eb5ae35503 to your computer and use it in GitHub Desktop.

Select an option

Save weissjeffm/fcd7e5b311eb5ae35503 to your computer and use it in GitHub Desktop.
In [7]:
def mytest():
print "running test"
def cleanup():
print "cleaning up test"
raise Exception({'msg': 'oh noes', 'cleanup': cleanup})
def pytest_exception_interact(e):
print "handling error"
e.message['cleanup']()
def pytest_test_runner(test):
try:
print "starting test"
test()
except Exception as e:
print "test failed"
pytest_exception_interact(e)
finally:
print "pytest cleaning up"
pytest_test_runner(mytest)
starting test
running test
test failed
handling error
cleaning up test
pytest cleaning up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment