@@ -719,25 +719,34 @@ def test_fix(foo):
719
719
result .stdout .fnmatch_lines (["*test_fix*" , "*fixture*'missing'*not found*" ])
720
720
721
721
722
- def test_store_except_info_on_eror ():
722
+ def test_store_except_info_on_error ():
723
723
""" Test that upon test failure, the exception info is stored on
724
724
sys.last_traceback and friends.
725
725
"""
726
- # Simulate item that raises a specific exception
727
- class ItemThatRaises (object ):
726
+ # Simulate item that might raise a specific exception, depending on `raise_error` class var
727
+ class ItemMightRaise (object ):
728
728
nodeid = 'item_that_raises'
729
+ raise_error = True
729
730
730
731
def runtest (self ):
731
- raise IndexError ('TEST' )
732
+ if self .raise_error :
733
+ raise IndexError ('TEST' )
732
734
try :
733
- runner .pytest_runtest_call (ItemThatRaises ())
735
+ runner .pytest_runtest_call (ItemMightRaise ())
734
736
except IndexError :
735
737
pass
736
738
# Check that exception info is stored on sys
737
739
assert sys .last_type is IndexError
738
740
assert sys .last_value .args [0 ] == 'TEST'
739
741
assert sys .last_traceback
740
742
743
+ # The next run should clear the exception info stored by the previous run
744
+ ItemMightRaise .raise_error = False
745
+ runner .pytest_runtest_call (ItemMightRaise ())
746
+ assert sys .last_type is None
747
+ assert sys .last_value is None
748
+ assert sys .last_traceback is None
749
+
741
750
742
751
def test_current_test_env_var (testdir , monkeypatch ):
743
752
pytest_current_test_vars = []
0 commit comments