From 64eb9ea670fd4d31e46e41ee397933fcad05886d Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 11:50:40 +0000 Subject: [PATCH 1/6] Modify test for new expected behaviour --- testing/test_runner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/test_runner.py b/testing/test_runner.py index 86e9bddff..301e11898 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -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): From 2ffbe41ae526b5367fca798e405fceab9bc57228 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:06:47 +0000 Subject: [PATCH 2/6] clear sys.last_traceback via del instead of = None --- src/_pytest/runner.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index c383146c3..67e28e905 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -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: From 9d1082bd302832fe7289dfbed53a81a17eccf05c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:13:36 +0000 Subject: [PATCH 3/6] Add changelog file. --- changelog/6255.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/6255.bugfix.rst diff --git a/changelog/6255.bugfix.rst b/changelog/6255.bugfix.rst new file mode 100644 index 000000000..831187feb --- /dev/null +++ b/changelog/6255.bugfix.rst @@ -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. From 8d686a8e460fe8dd513efe2632481587ce0d4ab9 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:14:19 +0000 Subject: [PATCH 4/6] Add self to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 14c465571..6e2f472fe 100644 --- a/AUTHORS +++ b/AUTHORS @@ -165,6 +165,7 @@ Marcelo Duarte Trevisani Marcin Bachry Marco Gorelli Mark Abramowitz +Mark Dickinson Markus Unterwaditzer Martijn Faassen Martin Altmayer From dbb8c146f041b4ffaa704097007d8bb1f160d990 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:22:34 +0000 Subject: [PATCH 5/6] Use proper reST attribute markup. --- changelog/6255.bugfix.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog/6255.bugfix.rst b/changelog/6255.bugfix.rst index 831187feb..6eb064ef3 100644 --- a/changelog/6255.bugfix.rst +++ b/changelog/6255.bugfix.rst @@ -1,3 +1,4 @@ -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. +Clear the :py:attr:`sys.last_traceback`, :py:attr:`sys.last_type` +and :py:attr:`sys.last_value` attributes by deleting them instead +of setting them to ``None``. This better matches the behaviour of +the Python standard library. From 82424c92708ed6fe9fba83ff4cbc3ce128e13494 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 21 Nov 2019 13:37:17 +0000 Subject: [PATCH 6/6] Fix reST markup. --- changelog/6255.bugfix.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/changelog/6255.bugfix.rst b/changelog/6255.bugfix.rst index 6eb064ef3..831187feb 100644 --- a/changelog/6255.bugfix.rst +++ b/changelog/6255.bugfix.rst @@ -1,4 +1,3 @@ -Clear the :py:attr:`sys.last_traceback`, :py:attr:`sys.last_type` -and :py:attr:`sys.last_value` attributes by deleting them instead -of setting them to ``None``. This better matches the behaviour of -the Python standard library. +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.