runner: avoid adding uninteresting entry to tracebacks

In these two cases which re-raise an immediately-caught exception, do
the re-raising with `raise` instead of `raise exc`, because the `raise
exc` adds an uninteresting entry to the exception's traceback (that of
itself), while `raise` doesn't.
This commit is contained in:
Ran Benita 2024-04-28 01:39:36 +03:00
parent 93c2cdf6d6
commit fc5c960304
1 changed files with 2 additions and 2 deletions

View File

@ -180,7 +180,7 @@ def pytest_runtest_call(item: Item) -> None:
assert e.__traceback__ is not None assert e.__traceback__ is not None
# Skip *this* frame # Skip *this* frame
sys.last_traceback = e.__traceback__.tb_next sys.last_traceback = e.__traceback__.tb_next
raise e raise
def pytest_runtest_teardown(item: Item, nextitem: Optional[Item]) -> None: def pytest_runtest_teardown(item: Item, nextitem: Optional[Item]) -> None:
@ -512,7 +512,7 @@ class SetupState:
col.setup() col.setup()
except TEST_OUTCOME as exc: except TEST_OUTCOME as exc:
self.stack[col] = (self.stack[col][0], exc) self.stack[col] = (self.stack[col][0], exc)
raise exc raise
def addfinalizer(self, finalizer: Callable[[], object], node: Node) -> None: def addfinalizer(self, finalizer: Callable[[], object], node: Node) -> None:
"""Attach a finalizer to the given node. """Attach a finalizer to the given node.