Skip to content

ExceptionGroup traceback of session fixture unlimitedly grows from test to test #12204

Closed

Description

@tkukushkin

My session fixture can raise ExceptionGroup and I see huge traceback which grows unlimitedly from test to test.

pip list:

iniconfig 2.0.0  
packaging 24.0   
pluggy    1.4.0  
pytest    8.1.1 

Operation system: macOS 14.3
Python: 3.12.0

Example:

import pytest

@pytest.fixture(scope='session', autouse=True)
def f1():
    raise ExceptionGroup('', [ValueError()])

def test_smth1():
    pass

def test_smth2():
    pass

def test_smth3():
    pass

With such code I get 495 lines of logs:

Details

============================= test session starts ==============================
platform darwin -- Python 3.12.0, pytest-8.0.0, pluggy-1.3.0
rootdir: /Users/tkukushkin/Projects/test/tests
configfile: pytest.ini
plugins: cov-4.1.0
collected 3 items

tests/test_foo.py EEE [100%]

==================================== ERRORS ====================================
_________________________ ERROR at setup of test_smth1 _________________________

  • Exception Group Traceback (most recent call last):
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 345, in from_call
    | result: Optional[TResult] = func()
    | ^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 266, in
    | lambda: ihook(item=item, **kwds), when=when, reraise=reraise
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 85, in pytest_runtest_setup
    | yield from unraisable_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 833, in pytest_runtest_setup
    | yield from self._runtest_for(item, "setup")
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 822, in _runtest_for
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/capture.py", line 877, in pytest_runtest_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 82, in pytest_runtest_setup
    | yield from thread_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 161, in pytest_runtest_setup
    | item.session._setupstate.setup(item)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 517, in setup
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 514, in setup
    | col.setup()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/python.py", line 1839, in setup
    | self._request._fillfixtures()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 693, in _fillfixtures
    | item.funcargs[argname] = self.getfixturevalue(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 547, in getfixturevalue
    | fixturedef = self._get_active_fixturedef(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 566, in _get_active_fixturedef
    | self._compute_fixture_value(fixturedef)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 652, in _compute_fixture_value
    | fixturedef.execute(request=subrequest)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1095, in execute
    | result = ihook.pytest_fixture_setup(fixturedef=self, request=request)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/setuponly.py", line 36, in pytest_fixture_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1149, in pytest_fixture_setup
    | result = call_fixture_func(fixturefunc, request, kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 923, in call_fixture_func
    | fixture_result = fixturefunc(**kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/Projects/test/tests/test_foo.py", line 6, in f1
    | raise ExceptionGroup('', [ValueError('foo')])
    | ExceptionGroup: (1 sub-exception)
    +-+---------------- 1 ----------------
    | ValueError: foo
    +------------------------------------
    _________________________ ERROR at setup of test_smth2 _________________________
  • Exception Group Traceback (most recent call last):
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 345, in from_call
    | result: Optional[TResult] = func()
    | ^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 266, in
    | lambda: ihook(item=item, **kwds), when=when, reraise=reraise
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 85, in pytest_runtest_setup
    | yield from unraisable_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 833, in pytest_runtest_setup
    | yield from self._runtest_for(item, "setup")
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 822, in _runtest_for
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/capture.py", line 877, in pytest_runtest_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 82, in pytest_runtest_setup
    | yield from thread_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 161, in pytest_runtest_setup
    | item.session._setupstate.setup(item)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 517, in setup
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 514, in setup
    | col.setup()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/python.py", line 1839, in setup
    | self._request._fillfixtures()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 693, in _fillfixtures
    | item.funcargs[argname] = self.getfixturevalue(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 547, in getfixturevalue
    | fixturedef = self._get_active_fixturedef(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 566, in _get_active_fixturedef
    | self._compute_fixture_value(fixturedef)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 652, in _compute_fixture_value
    | fixturedef.execute(request=subrequest)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1085, in execute
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 345, in from_call
    | result: Optional[TResult] = func()
    | ^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 266, in
    | lambda: ihook(item=item, **kwds), when=when, reraise=reraise
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 85, in pytest_runtest_setup
    | yield from unraisable_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 833, in pytest_runtest_setup
    | yield from self._runtest_for(item, "setup")
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 822, in _runtest_for
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/capture.py", line 877, in pytest_runtest_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 82, in pytest_runtest_setup
    | yield from thread_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 161, in pytest_runtest_setup
    | item.session._setupstate.setup(item)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 517, in setup
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 514, in setup
    | col.setup()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/python.py", line 1839, in setup
    | self._request._fillfixtures()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 693, in _fillfixtures
    | item.funcargs[argname] = self.getfixturevalue(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 547, in getfixturevalue
    | fixturedef = self._get_active_fixturedef(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 566, in _get_active_fixturedef
    | self._compute_fixture_value(fixturedef)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 652, in _compute_fixture_value
    | fixturedef.execute(request=subrequest)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1095, in execute
    | result = ihook.pytest_fixture_setup(fixturedef=self, request=request)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/setuponly.py", line 36, in pytest_fixture_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1149, in pytest_fixture_setup
    | result = call_fixture_func(fixturefunc, request, kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 923, in call_fixture_func
    | fixture_result = fixturefunc(**kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/Projects/test/tests/test_foo.py", line 6, in f1
    | raise ExceptionGroup('', [ValueError('foo')])
    | ExceptionGroup: (1 sub-exception)
    +-+---------------- 1 ----------------
    | ValueError: foo
    +------------------------------------
    _________________________ ERROR at setup of test_smth3 _________________________
  • Exception Group Traceback (most recent call last):
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 345, in from_call
    | result: Optional[TResult] = func()
    | ^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 266, in
    | lambda: ihook(item=item, **kwds), when=when, reraise=reraise
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 85, in pytest_runtest_setup
    | yield from unraisable_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 833, in pytest_runtest_setup
    | yield from self._runtest_for(item, "setup")
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 822, in _runtest_for
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/capture.py", line 877, in pytest_runtest_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 82, in pytest_runtest_setup
    | yield from thread_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 161, in pytest_runtest_setup
    | item.session._setupstate.setup(item)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 517, in setup
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 514, in setup
    | col.setup()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/python.py", line 1839, in setup
    | self._request._fillfixtures()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 693, in _fillfixtures
    | item.funcargs[argname] = self.getfixturevalue(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 547, in getfixturevalue
    | fixturedef = self._get_active_fixturedef(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 566, in _get_active_fixturedef
    | self._compute_fixture_value(fixturedef)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 652, in _compute_fixture_value
    | fixturedef.execute(request=subrequest)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1085, in execute
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 345, in from_call
    | result: Optional[TResult] = func()
    | ^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 266, in
    | lambda: ihook(item=item, **kwds), when=when, reraise=reraise
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 85, in pytest_runtest_setup
    | yield from unraisable_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 833, in pytest_runtest_setup
    | yield from self._runtest_for(item, "setup")
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 822, in _runtest_for
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/capture.py", line 877, in pytest_runtest_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 82, in pytest_runtest_setup
    | yield from thread_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 161, in pytest_runtest_setup
    | item.session._setupstate.setup(item)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 517, in setup
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 514, in setup
    | col.setup()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/python.py", line 1839, in setup
    | self._request._fillfixtures()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 693, in _fillfixtures
    | item.funcargs[argname] = self.getfixturevalue(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 547, in getfixturevalue
    | fixturedef = self._get_active_fixturedef(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 566, in _get_active_fixturedef
    | self._compute_fixture_value(fixturedef)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 652, in _compute_fixture_value
    | fixturedef.execute(request=subrequest)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1085, in execute
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 345, in from_call
    | result: Optional[TResult] = func()
    | ^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 266, in
    | lambda: ihook(item=item, **kwds), when=when, reraise=reraise
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 85, in pytest_runtest_setup
    | yield from unraisable_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 833, in pytest_runtest_setup
    | yield from self._runtest_for(item, "setup")
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/logging.py", line 822, in _runtest_for
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/capture.py", line 877, in pytest_runtest_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 82, in pytest_runtest_setup
    | yield from thread_exception_runtest_hook()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    | yield
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 161, in pytest_runtest_setup
    | item.session._setupstate.setup(item)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 517, in setup
    | raise exc
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/runner.py", line 514, in setup
    | col.setup()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/python.py", line 1839, in setup
    | self._request._fillfixtures()
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 693, in _fillfixtures
    | item.funcargs[argname] = self.getfixturevalue(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 547, in getfixturevalue
    | fixturedef = self._get_active_fixturedef(argname)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 566, in _get_active_fixturedef
    | self._compute_fixture_value(fixturedef)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 652, in _compute_fixture_value
    | fixturedef.execute(request=subrequest)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1095, in execute
    | result = ihook.pytest_fixture_setup(fixturedef=self, request=request)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_hooks.py", line 493, in call
    | return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_manager.py", line 115, in _hookexec
    | return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 113, in _multicall
    | raise exception.with_traceback(exception.traceback)
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 96, in _multicall
    | teardown.throw(exception) # type: ignore[union-attr]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/setuponly.py", line 36, in pytest_fixture_setup
    | return (yield)
    | ^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/pluggy/_callers.py", line 77, in _multicall
    | res = hook_impl.function(*args)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 1149, in pytest_fixture_setup
    | result = call_fixture_func(fixturefunc, request, kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/.pyenv/versions/3.12.0/lib/python3.12/site-packages/_pytest/fixtures.py", line 923, in call_fixture_func
    | fixture_result = fixturefunc(**kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^
    | File "/Users/tkukushkin/Projects/test/tests/test_foo.py", line 6, in f1
    | raise ExceptionGroup('', [ValueError('foo')])
    | ExceptionGroup: (1 sub-exception)
    +-+---------------- 1 ----------------
    | ValueError: foo
    +------------------------------------
    =========================== short test summary info ============================
    ERROR tests/test_foo.py::test_smth1 - ExceptionGroup: (1 sub-exception)
    ERROR tests/test_foo.py::test_smth2 - ExceptionGroup: (1 sub-exception)
    ERROR tests/test_foo.py::test_smth3 - ExceptionGroup: (1 sub-exception)
    ============================== 3 errors in 0.02s ===============================

Traceback of first test: 95 lines
Traceback of second test: 159 lines
Traceback of third test: 223 lines

In more complex example with several hundred of tests I got 2.7 GiB logs :-)

Activity

  1. bluetech commented on Apr 27, 2024

    @bluetech
    Member

    Interesting, thanks for the report.

    Problem

    First, this is actually not specific to ExceptionGroup, this happens for every exception, it's just that we haven't implemented pretty-printing for ExceptionGroup yet so it's more visible. But with --tb=native can see the same thing for Exception as well.

    So what happens is, when the session fixture is first requested by the first test, it is executed, raises, and the exception is cached as the result of the fixture. When the next test requests the fixture, we see the cached exception and re-raise it.

    But in python, exception objects are mutable; whenever you raise an exception, it appends entries to the traceback. So on every raise of the cached exception, the traceback gets longer and longer...

    Example

    import traceback
    
    def bad():
        1 / 0
    
    cache = None
    def foo():
        global cache
        if cache is not None:
            raise cache
        try:
            bad()
        except Exception as exc:
            cache = exc
            raise
    
    try:
        foo()
    except Exception:
        traceback.print_exc()
    
    print('\n')
    try:
        foo()
    except Exception:
        traceback.print_exc()
    
    print('\n')
    try:
        foo()
    except Exception:
        traceback.print_exc()

    Output:

    Traceback (most recent call last):
      File "/home/ran/src/pytest/yy.py", line 18, in <module>
        foo()
      File "/home/ran/src/pytest/yy.py", line 12, in foo
        bad()
      File "/home/ran/src/pytest/yy.py", line 4, in bad
        1 / 0
        ~~^~~
    ZeroDivisionError: division by zero
    
    
    Traceback (most recent call last):
      File "/home/ran/src/pytest/yy.py", line 24, in <module>
        foo()
      File "/home/ran/src/pytest/yy.py", line 10, in foo
        raise cache
      File "/home/ran/src/pytest/yy.py", line 18, in <module>
        foo()
      File "/home/ran/src/pytest/yy.py", line 12, in foo
        bad()
      File "/home/ran/src/pytest/yy.py", line 4, in bad
        1 / 0
        ~~^~~
    ZeroDivisionError: division by zero
    
    
    Traceback (most recent call last):
      File "/home/ran/src/pytest/yy.py", line 30, in <module>
        foo()
      File "/home/ran/src/pytest/yy.py", line 10, in foo
        raise cache
      File "/home/ran/src/pytest/yy.py", line 24, in <module>
        foo()
      File "/home/ran/src/pytest/yy.py", line 10, in foo
        raise cache
      File "/home/ran/src/pytest/yy.py", line 18, in <module>
        foo()
      File "/home/ran/src/pytest/yy.py", line 12, in foo
        bad()
      File "/home/ran/src/pytest/yy.py", line 4, in bad
        1 / 0
        ~~^~~
    ZeroDivisionError: division by zero
    

    Solution

    The solution is to keep the original traceback, and re-raise with it.

    Turns out, this is how it was done in pytest < 8.0, before I mindlessly broke it in #11208 / 9d0ddb4. So I need to revert this.

    BTW, there is another place where we do this raising of cached exception thing, in SetupState.setup(). This one I also broke, but a few years earlier, in 978b315. I will fix this as well.

  2. added 2 commits that reference this issue on Apr 28, 2024
    0b91d5e
    3e81cb2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions