From 9726fafa98885fd3bec3972da3bda5f5ce91afdf Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Sat, 21 Mar 2015 09:26:35 +0100 Subject: [PATCH] allow postmortem debugging on failed test --- _pytest/runner.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/_pytest/runner.py b/_pytest/runner.py index 2932f14c3..8accd3b0c 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -86,7 +86,17 @@ def pytest_runtest_setup(item): item.session._setupstate.prepare(item) def pytest_runtest_call(item): - item.runtest() + try: + item.runtest() + except Exception: + # Store trace info to allow postmortem debugging + type, value, tb = sys.exc_info() + tb = tb.tb_next # Skip *this* frame + sys.last_type = type + sys.last_value = value + sys.last_traceback = tb + del tb # Get rid of it in this namespace + raise def pytest_runtest_teardown(item, nextitem): item.session._setupstate.teardown_exact(item, nextitem)