From 92962b286b2e1c1165fd6a21998190dc00cd72f8 Mon Sep 17 00:00:00 2001 From: robotherapist Date: Mon, 5 Feb 2024 21:55:47 +0100 Subject: [PATCH] Add test and changelog --- changelog/11850.improvement.rst | 1 + testing/test_runner.py | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 changelog/11850.improvement.rst diff --git a/changelog/11850.improvement.rst b/changelog/11850.improvement.rst new file mode 100644 index 000000000..8939b7502 --- /dev/null +++ b/changelog/11850.improvement.rst @@ -0,0 +1 @@ +Added the new `sys.last_exc` value to `pytest_runtest_call()` in `src/_pytest/runner.py`. \ No newline at end of file diff --git a/testing/test_runner.py b/testing/test_runner.py index 6b2b3105b..91534c266 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -926,6 +926,8 @@ def test_store_except_info_on_error() -> None: # Check that exception info is stored on sys assert sys.last_type is IndexError assert isinstance(sys.last_value, IndexError) + assert isinstance(sys.last_exc, IndexError) + assert sys.last_value.args[0] == "TEST" assert sys.last_traceback @@ -934,6 +936,7 @@ def test_store_except_info_on_error() -> None: runner.pytest_runtest_call(ItemMightRaise()) # type: ignore[arg-type] assert not hasattr(sys, "last_type") assert not hasattr(sys, "last_value") + assert not hasattr(sys, "last_exc") assert not hasattr(sys, "last_traceback")