Repository navigation
Create fresh context managers in the conditional-raising example - #15480
Open
hariomkhonde108 wants to merge 2 commits into
Open
hariomkhonde108 wants to merge 2 commits into
hariomkhonde108 wants to merge 2 commits into
Conversation
Assisted-by: OpenAI Codex (GPT-6)
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Assisted-by: OpenAI Codex (GPT-6)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13410.
The conditional-raising example creates a
pytest.raises()context manager during collection and stores it as a parameter. After the exception case runs, the collected test item can keep the context manager, traceback, and test-local objects alive.The example now parametrizes context-manager factories and calls the factory inside the test. It also explains why the context manager should be created there.
Testing (run with Codex)
Ran the updated documentation example as a standalone pytest file. All four cases passed.
Used weak references to track test-local objects while keeping the collected items alive. The original example retained the exception case's object. The revised example released all four after garbage collection.
Full pytest suite on Python 3.12: 4,665 passed, 160 skipped, 13 xfailed, and 1 xpassed.
Applicable pre-commit checks passed for the changed file.
The strict Sphinx build reported the same two Pluggy cross-reference warnings on the original and patched checkouts.
Checklist
AI assistance from OpenAI Codex (GPT‑6) was used to prepare the patch, verification script, and this draft.