Skip to content

Deprecate calling pytest.skip() during teardown - #15479

Open
Pranjalitem189 wants to merge 2 commits into
pytest-dev:mainfrom
Pranjalitem189:skip-in-teardown-deprecation
Open

Pranjalitem189 wants to merge 2 commits into
pytest-dev:mainfrom
Pranjalitem189:skip-in-teardown-deprecation

Conversation

@Pranjalitem189

@Pranjalitem189 Pranjalitem189 commented Nov 28, 2026 •

Copy link
Copy Markdown

A skip raised during teardown, for example after the yield of a fixture, happens after the test has already run, so the test was reported as both passed and skipped.

Skips raised during teardown, alone or as an exception group made only of skips, now issue a PytestRemovedIn10Warning pointing at the skip call. The reported outcome does not change. If a warnings filter turns the warning into an error, the teardown is reported as an error at the skip call, which previews the planned behaviour.

Skips during setup or in the test itself are not affected.

Fixes #15289

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 28, 2026

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

This is the first stage we wanted for #15289: warn now, error in pytest 10. A few things before merge:

  1. doc/en/deprecations.rst: .. deprecated:: 10.0 should be the release that introduces the deprecation (the next 9.x), not the removal version.
  2. codecov/patch fails. The crash is None fallback in _warn_skip_during_teardown has no test. Please cover it (a fixture with __tracebackhide__ = True) or drop the branch.
  3. The PR template asks that AI agents used are credited with Co-authored-by commit trailers, see https://github.com/pytest-dev/pytest/blob/main/CONTRIBUTING.rst#aillm-assisted-contributions-policy. If an agent helped, please add the trailer.

Generated by Claude Code

@Pranjalitem189

Copy link
Copy Markdown
Author

Thanks for the review! All three points are addressed:

Deprecated version: changed .. deprecated:: to 9.3. The warning stays PytestRemovedIn10Warning, so it becomes an error in pytest 10 as planned.
Coverage: I removed the crash is None fallback instead of testing it, because it can't be reached. The skip's traceback starts at pytest_runtest_teardown, which is never hidden, so _getreprcrash() always finds a location. It's an assert now, the same way TestReport.from_item_and_call handles skips. I also added the tracebackhide fixture test you suggested (test_hidden_fixture_teardown_skip_warns). It still warns, at the nearest visible frame.

Copy link
Copy Markdown
Member

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

The code changes look good now, thanks for checking the reachability of that branch. Your reply says all three points are addressed, but the third one isn't mentioned and neither commit has a Co-authored-by trailer. Did you use an AI agent for this PR or its replies? If yes, please add the trailer as the template asks (https://github.com/pytest-dev/pytest/blob/main/CONTRIBUTING.rst#aillm-assisted-contributions-policy). If not, just say so and I'll approve.


Generated by Claude Code

@Pranjalitem189
Pranjalitem189 force-pushed the skip-in-teardown-deprecation branch from 1b5a3eb to f783f73 Compare November 28, 2026 22:09
@Pranjalitem189

Pranjalitem189 commented Nov 28, 2026 •

Copy link
Copy Markdown
Author

@RonnyPfannschmidt I had used a co-author in my review fix and have added the co-author. Thanks for the review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn when calling pytest.skip() during teardown?

2 participants