|
2 | 2 | import functools |
3 | 3 | import inspect |
4 | 4 | import os |
5 | | -import sys |
6 | 5 | import warnings |
7 | 6 | from collections import defaultdict |
8 | 7 | from collections import deque |
9 | 8 | from contextlib import suppress |
10 | 9 | from pathlib import Path |
11 | | -from types import TracebackType |
12 | 10 | from typing import Any |
13 | 11 | from typing import Callable |
14 | 12 | from typing import cast |
|
27 | 25 | from typing import Sequence |
28 | 26 | from typing import Set |
29 | 27 | from typing import Tuple |
30 | | -from typing import Type |
31 | 28 | from typing import TYPE_CHECKING |
32 | 29 | from typing import TypeVar |
33 | 30 | from typing import Union |
|
99 | 96 | None, |
100 | 97 | # Cache key. |
101 | 98 | object, |
102 | | - # Exc info if raised. |
103 | | - Tuple[Type[BaseException], BaseException, TracebackType], |
| 99 | + # Exception if raised. |
| 100 | + BaseException, |
104 | 101 | ], |
105 | 102 | ] |
106 | 103 |
|
@@ -1085,13 +1082,13 @@ def execute(self, request: SubRequest) -> FixtureValue: |
1085 | 1082 |
|
1086 | 1083 | my_cache_key = self.cache_key(request) |
1087 | 1084 | if self.cached_result is not None: |
| 1085 | + cache_key = self.cached_result[1] |
1088 | 1086 | # note: comparison with `==` can fail (or be expensive) for e.g. |
1089 | 1087 | # numpy arrays (#6497). |
1090 | | - cache_key = self.cached_result[1] |
1091 | 1088 | if my_cache_key is cache_key: |
1092 | 1089 | if self.cached_result[2] is not None: |
1093 | | - _, val, tb = self.cached_result[2] |
1094 | | - raise val.with_traceback(tb) |
| 1090 | + exc = self.cached_result[2] |
| 1091 | + raise exc |
1095 | 1092 | else: |
1096 | 1093 | result = self.cached_result[0] |
1097 | 1094 | return result |
@@ -1156,14 +1153,12 @@ def pytest_fixture_setup( |
1156 | 1153 | my_cache_key = fixturedef.cache_key(request) |
1157 | 1154 | try: |
1158 | 1155 | result = call_fixture_func(fixturefunc, request, kwargs) |
1159 | | - except TEST_OUTCOME: |
1160 | | - exc_info = sys.exc_info() |
1161 | | - assert exc_info[0] is not None |
1162 | | - if isinstance( |
1163 | | - exc_info[1], skip.Exception |
1164 | | - ) and not fixturefunc.__name__.startswith("xunit_setup"): |
1165 | | - exc_info[1]._use_item_location = True # type: ignore[attr-defined] |
1166 | | - fixturedef.cached_result = (None, my_cache_key, exc_info) |
| 1156 | + except TEST_OUTCOME as e: |
| 1157 | + if isinstance(e, skip.Exception) and not fixturefunc.__name__.startswith( |
| 1158 | + "xunit_setup" |
| 1159 | + ): |
| 1160 | + e._use_item_location = True |
| 1161 | + fixturedef.cached_result = (None, my_cache_key, e) |
1167 | 1162 | raise |
1168 | 1163 | fixturedef.cached_result = (result, my_cache_key, None) |
1169 | 1164 | return result |
|
0 commit comments