summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2018-04-04 20:36:07 -0300
committerBruno Oliveira <nicoddemus@gmail.com>2018-04-04 20:36:07 -0300
commitba407b5eb601da54a893df769fd61e65a718bb66 (patch)
tree2733094c906b184a7e6fef36fd7c9f570cedfc29 /testing
parentad0b4330e7e9f29ea8961f62ebde3fab65c6cf4c (diff)
downloadpytest-ba407b5eb601da54a893df769fd61e65a718bb66.tar.gz
Clear sys.last_* attributes before running an item
Otherwise we will keep the last failed exception around forever Related to #2798
Diffstat (limited to 'testing')
-rw-r--r--testing/test_runner.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/testing/test_runner.py b/testing/test_runner.py
index a3bd8ecb4..7c179b1f2 100644
--- a/testing/test_runner.py
+++ b/testing/test_runner.py
@@ -719,18 +719,20 @@ def test_makereport_getsource_dynamic_code(testdir, monkeypatch):
result.stdout.fnmatch_lines(["*test_fix*", "*fixture*'missing'*not found*"])
-def test_store_except_info_on_eror():
+def test_store_except_info_on_error():
""" Test that upon test failure, the exception info is stored on
sys.last_traceback and friends.
"""
- # Simulate item that raises a specific exception
- class ItemThatRaises(object):
+ # Simulate item that might raise a specific exception, depending on `raise_error` class var
+ class ItemMightRaise(object):
nodeid = 'item_that_raises'
+ raise_error = True
def runtest(self):
- raise IndexError('TEST')
+ if self.raise_error:
+ raise IndexError('TEST')
try:
- runner.pytest_runtest_call(ItemThatRaises())
+ runner.pytest_runtest_call(ItemMightRaise())
except IndexError:
pass
# Check that exception info is stored on sys
@@ -738,6 +740,13 @@ def test_store_except_info_on_eror():
assert sys.last_value.args[0] == 'TEST'
assert sys.last_traceback
+ # The next run should clear the exception info stored by the previous run
+ ItemMightRaise.raise_error = False
+ runner.pytest_runtest_call(ItemMightRaise())
+ assert sys.last_type is None
+ assert sys.last_value is None
+ assert sys.last_traceback is None
+
def test_current_test_env_var(testdir, monkeypatch):
pytest_current_test_vars = []