GeezerVison is showing github.com — Double `pytest.skip` leads to failure · Issue #13537 · pytest-dev/pytest
Double pytest.skip leads to failure #13537DescriptionHello everyone.
I think the following is a bug.
@pytest.fixture
def fixA():
yield
pytest.skip(reason="A")
@pytest.fixture
def fixB():
yield
pytest.skip(reason="B")
def test_skip(fixA, fixB): # FAILS
assert True
Gives the following error report (removed tracebacks).
____________________________ ERROR at teardown of test_skip _____________________________
+ Exception Group Traceback (most recent call last):
| <traceback>
| BaseExceptionGroup: errors while tearing down <Function test_skip> (2 sub-exceptions)
+-+---------------- 1 ----------------
| <traceback>
| Skipped: A
+---------------- 2 ----------------
| <traceback>
| Skipped: B
+------------------------------------
Maybe pytest checks for the error raised being of the type of skips, and thus here it bugs because it's an ExceptionGroup and not a skip type? I'm just very wildly guessing, I don't know the internals of pytest. Activitychanged the title [-]Double `pytest.skip` lead to failure[/-] [+]Double `pytest.skip` leads to failure[/+] on Jun 18, 2025The-Compiler commented on Jun 18, 2025 In pytest 7.2.2 (or when removing fixB), this results in 1 passed, 1 skipped (which is somewhat confusing but another long-standing issue).
With pytest 7.3.0 and later, this errors in the same way you mention. Bisected to 3a68c08:
And I think your guess is spot-on, e.g. around here:
|
skip_exceptions = [Skipped] |
|
unittest = sys.modules.get("unittest") |
|
if unittest is not None: |
|
skip_exceptions.append(unittest.SkipTest) |
|
if isinstance(call.excinfo.value, tuple(skip_exceptions)): |
|
outcome = "skipped" |
|
r_ = collector._repr_failure_py(call.excinfo, "line") |
|
assert isinstance(r_, ExceptionChainRepr), repr(r_) |
|
r = r_.reprcrash |
|
assert r |
|
longrepr = (str(r.path), r.lineno, r.message) |
|
else: |
|
outcome = "failed" |
I suspect this might also happen with other outcome exceptions. Maybe we should immediately raise the first outcome exception as a special case rather than grouping those? Perhaps conditionally as long as there are no other non-outcome exceptions that happened?
cc @Zac-HD @jakkdl who did a lot of work around exception groups RonnyPfannschmidt commented on Jun 18, 2025 We should consider exception group's with only skip as skip Reacted by Zac Hatfield-Dodds ego-thales commented on Jun 18, 2025 Ok great!
Maybe we should immediately raise the first outcome exception as a special case rather than grouping those? Perhaps conditionally as long as there are no other non-outcome exceptions that happened?
I was thinking about this and I don't think the desired behaviour is trivial to define. For example, we might want to skip if there are only skips, but we might also want to allow fixtures to skip even if an inner fixture failed? Like a kind of "catching fixture". It seems far fetched, but I think there's potentially something to clarify here.
Also, we might want to skip at the first skip encountered, OR we might want to allow outermost fixture to still fail the test even if an inner fixture skipped it?
So as I see it, it's a discussion that needs to happen. RonnyPfannschmidt commented on Jun 18, 2025 The groupings was added so exceptions no longer get lost
Now we need to account for that in places Zac-HD commented on Jun 18, 2025 if isinstance(exc := call.excinfo.value, tuple(skip_exceptions)) or (
isinstance(exc, BaseExceptionGroup) and exc.subgroup(skip_exceptions)
):
once we drop Python 3.10, the new except* syntax should also make it easier. RonnyPfannschmidt commented on Jun 20, 2025 I did a quick excursion to exitstack
Exitstack nests the errors by manipulation of the context so it behaves as if it was nested
We should consider whether we want that or groups in general
Based on the behavior of exception groups i slightly prefer the idea of eventually handling those from groups Zac-HD commented on Jun 20, 2025 We'll need to handle ExceptionGroups anyway, in case the user calls pytest.skip() from inside an asyncio.TaskGroup context manager (among other cases) RonnyPfannschmidt commented on Jun 20, 2025 gomri15 commented on Sep 18, 2025 would love to take a crack at this now that i've made some progress with pytest.exit().
could you assign it to me and in general should i wait to be assigned to something before i start working on it? Zac-HD commented on Sep 18, 2025 open source projects almost never assign issues - it's very rare to see duplicate PRs for an issue more than a few days old, and so it's not worth the overhead in notifications etc. Which means, feel free to just open a PR! added a commit that references this issue on Sep 21, 2025This issue will close once commit 91f73f4 is merged into the 'main' branch.91f73f4 added 3 commits that reference this issue on Sep 21, 2025This issue will close once commit 0380548 is merged into the 'main' branch.0380548 This issue will close once commit 90fba0d is merged into the 'main' branch.90fba0d This issue will close once commit 959a89f is merged into the 'main' branch.959a89f added 5 commits that reference this issue on Oct 15, 2025This issue will close once commit 6ed264c is merged into the 'main' branch.6ed264c This issue will close once commit 9adef4b is merged into the 'main' branch.9adef4b This issue will close once commit 2d37732 is merged into the 'main' branch.2d37732 This issue will close once commit 11ad3fb is merged into the 'main' branch.11ad3fb This issue will close once commit ff07ff6 is merged into the 'main' branch.ff07ff6 added a commit that references this issue on Oct 28, 2025This issue will close once commit e26c0ae is merged into the 'main' branch.e26c0ae
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|