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 Marcin Bachry
Marco Gorelli Marco Gorelli
Mark Abramowitz Mark Abramowitz
Mark Dickinson
Markus Unterwaditzer Markus Unterwaditzer
Martijn Faassen Martijn Faassen
Martin Altmayer 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): def pytest_runtest_call(item):
_update_current_test_var(item, "call") _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: try:
item.runtest() item.runtest()
except Exception: 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 # The next run should clear the exception info stored by the previous run
ItemMightRaise.raise_error = False ItemMightRaise.raise_error = False
runner.pytest_runtest_call(ItemMightRaise()) runner.pytest_runtest_call(ItemMightRaise())
assert sys.last_type is None assert not hasattr(sys, "last_type")
assert sys.last_value is None assert not hasattr(sys, "last_value")
assert sys.last_traceback is None assert not hasattr(sys, "last_traceback")
def test_current_test_env_var(testdir, monkeypatch): def test_current_test_env_var(testdir, monkeypatch):