Skip to content

Create fresh context managers in the conditional-raising example - #15480

Open
hariomkhonde108 wants to merge 2 commits into
pytest-dev:mainfrom
hariomkhonde108:docs/13410-fresh-raises-context
Open

hariomkhonde108 wants to merge 2 commits into
pytest-dev:mainfrom
hariomkhonde108:docs/13410-fresh-raises-context

Conversation

@hariomkhonde108

Copy link
Copy Markdown

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

  • Updated the documentation example.
  • Verified the example and the reported retention with a local check.
  • Allow maintainers to push and squash when merging.
  • Linked the issue above.
  • Credited OpenAI Codex (GPT-6) in the commit trailer.

AI assistance from OpenAI Codex (GPT‑6) was used to prepare the patch, verification script, and this draft.

Copilot AI balanced review requested due to automatic review settings November 28, 2026 08:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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

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.

The documented pattern for parametrizing conditional raising leaks a lot of memory

2 participants