Skip to content

Fix doctest option flags leaking between docstrings - #15033

Open
barveP wants to merge 1 commit into
pytest-dev:mainfrom
barveP:codex/fix-doctest-option-leak
Open

barveP wants to merge 1 commit into
pytest-dev:mainfrom
barveP:codex/fix-doctest-option-leak

Conversation

@barveP

@barveP barveP commented Sep 16, 2026

Copy link
Copy Markdown

Closes #9924.

Doctests within a module share a runner. When an example exits early, its comparison flags can remain changed and affect a later docstring. This can cause false passes or false failures, depending on which option was enabled or disabled.

Save the incoming flags before running each doctest and restore them in finally. This keeps an early exit from changing the next docstring's comparison settings.

The 16 regression cases exercise NUMBER and ELLIPSIS, output mismatches, unexpected exceptions, skips and xfails. They also check both continue-on-failure modes. Before the fix, 10 cases fail and six compatibility checks pass; afterward, all 16 pass.

Checks completed on macOS:

  • Full Python 3.13 suite (tox -e py313 -- -q): 4,618 passed, 51 skipped, 15 xfailed and 5 xpassed.
  • Python 3.12 doctest suite (tox -e py312 -- testing/test_doctest.py -q): 160 passed and 1 xfailed.
  • Repository linting and type checks (tox -e linting): passed.

Implemented and tested with the help from Codex.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 16, 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.

looks good, please ensure the ai attribution

@barveP

barveP commented Sep 16, 2026

Copy link
Copy Markdown
Author

@RonnyPfannschmidt thanks for reviewing! added the AI attribution to the PR description.

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

thanks - for future reference - depending on the attribution policies and ai policies of a project it tends to be a good idea to pick where to add coAuthored/AIAssisted trailers or not

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.

Leakage of NUMBER option out of docstring scope

2 participants