Skip to content

gh-163094: restore doctest option flags when a runner raises - #163095

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-doctest-runner-option-flags
Open

tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-doctest-runner-option-flags

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

restore the option flags when a doctest runner raises an exception.

suirindo commented Dec 3, 2026

Copy link
Copy Markdown

Would it be worth covering this with a plain DocTestRunner as well as DebugRunner? In a focused check, a custom out callback raised while reporting a failing example with +ELLIPSIS. On the base revision, the same runner then incorrectly passed a second example expecting a... for actual. On 253e9f4, the second example correctly failed. That would give the finally block coverage for exceptions from a user-supplied writer, too.

AI assistance: focused verification and drafting.

@efanntyo

efanntyo commented Dec 4, 2026

Copy link
Copy Markdown

A second restoration direction would help alongside the +ELLIPSIS/zero-default case and the writer-exception suggestion above: start with a nonzero runner default, then remove that flag on an example that raises UnexpectedException.

On CPython 3.12.16/Linux I ran a DebugRunner(optionflags=doctest.ELLIPSIS) against:

source = ">>> raise ValueError('boom')  # doctest: -ELLIPSIS\n"

After catching doctest.UnexpectedException, runner.optionflags is 0 instead of the original ELLIPSIS value (8). Reusing it for >>> print('actual') with expected a... then raises DocTestFailure, although that second test should pass with the original runner default.

This covers a different exception route and guards restoring the saved value, rather than accidentally resetting flags to zero. A regression can assert the flags immediately after UnexpectedException and then the successful second run. I reviewed 253e9f4 but only executed the installed-runtime control; no PR-head/full-main verification claimed. AI-assisted probe and drafting.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants