diff --git a/changelog/11850.improvement.rst b/changelog/11850.improvement.rst index 8939b7502..3c1f35a5f 100644 --- a/changelog/11850.improvement.rst +++ b/changelog/11850.improvement.rst @@ -1 +1 @@ -Added the new `sys.last_exc` value to `pytest_runtest_call()` in `src/_pytest/runner.py`. \ No newline at end of file +Added the new `sys.last_exc` value to `pytest_runtest_call()` in `src/_pytest/runner.py`. diff --git a/testing/test_runner.py b/testing/test_runner.py index 91534c266..a8f396a79 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -926,7 +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) + if sys.version_info >= (3,12,0): + assert isinstance(sys.last_exc, IndexError) assert sys.last_value.args[0] == "TEST" assert sys.last_traceback @@ -936,7 +937,8 @@ 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") + if sys.version_info >= (3,12,0): + assert not hasattr(sys, "last_exc") assert not hasattr(sys, "last_traceback")