Test that upon test failure, the exception info is stored on sys.last_traceback and friends.
()
| 878 | |
| 879 | |
| 880 | def test_store_except_info_on_error() -> None: |
| 881 | """Test that upon test failure, the exception info is stored on |
| 882 | sys.last_traceback and friends.""" |
| 883 | # Simulate item that might raise a specific exception, depending on `raise_error` class var |
| 884 | class ItemMightRaise: |
| 885 | nodeid = "item_that_raises" |
| 886 | raise_error = True |
| 887 | |
| 888 | def runtest(self): |
| 889 | if self.raise_error: |
| 890 | raise IndexError("TEST") |
| 891 | |
| 892 | try: |
| 893 | runner.pytest_runtest_call(ItemMightRaise()) # type: ignore[arg-type] |
| 894 | except IndexError: |
| 895 | pass |
| 896 | # Check that exception info is stored on sys |
| 897 | assert sys.last_type is IndexError |
| 898 | assert isinstance(sys.last_value, IndexError) |
| 899 | assert sys.last_value.args[0] == "TEST" |
| 900 | assert sys.last_traceback |
| 901 | |
| 902 | # The next run should clear the exception info stored by the previous run |
| 903 | ItemMightRaise.raise_error = False |
| 904 | runner.pytest_runtest_call(ItemMightRaise()) # type: ignore[arg-type] |
| 905 | assert not hasattr(sys, "last_type") |
| 906 | assert not hasattr(sys, "last_value") |
| 907 | assert not hasattr(sys, "last_traceback") |
| 908 | |
| 909 | |
| 910 | def test_current_test_env_var(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: |
nothing calls this directly
no test coverage detected