Remove sys.last_traceback attribute using del instead of settin… (#6256)

Remove sys.last_traceback attribute using del instead of setting to None
This commit is contained in:
Bruno Oliveira 2019-11-21 11:16:19 -03:00 committed by GitHub
commit f1ac0eeef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 4 deletions

View File

@ -165,6 +165,7 @@ Marcelo Duarte Trevisani
Marcin Bachry
Marco Gorelli
Mark Abramowitz
Mark Dickinson
Markus Unterwaditzer
Martijn Faassen
Martin Altmayer

View File

@ -0,0 +1,3 @@
Clear the ``sys.last_traceback``, ``sys.last_type`` and ``sys.last_value``
attributes by deleting them instead of setting them to ``None``. This better
matches the behaviour of the Python standard library.

View File

@ -121,7 +121,12 @@ def pytest_runtest_setup(item):
def pytest_runtest_call(item):
_update_current_test_var(item, "call")
sys.last_type, sys.last_value, sys.last_traceback = (None, None, None)
try:
del sys.last_type
del sys.last_value
del sys.last_traceback
except AttributeError:
pass
try:
item.runtest()
except Exception:

View File

@ -900,9 +900,9 @@ def test_store_except_info_on_error():
# 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
assert not hasattr(sys, "last_type")
assert not hasattr(sys, "last_value")
assert not hasattr(sys, "last_traceback")
def test_current_test_env_var(testdir, monkeypatch):