GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-108885: Report the examples of a doctest run by unittest by serhiy-storchaka · Pull Request #155377 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 8, 2026

Copy link
Copy Markdown
Member

DocTestCase.runTest() runs the examples with verbose=False, so there is no way to ask unittest for the details which doctest reports on its own. It now takes the verbosity from the test result, and reports every example if the test runner is asked for more than the test names.

$ ./python -m test -vv test_difflib
...
get_opcodes (difflib.SequenceMatcher)
Doctest: difflib.SequenceMatcher.get_opcodes ...
Trying:
    a = "qabxcd"
Expecting nothing
ok
...
get_opcodes (difflib.SequenceMatcher)
Doctest: difflib.SequenceMatcher.get_opcodes ... ok

The examples are written to the stream of the test runner, not to the standard output, so that they are not lost when the result buffers the output of the test.

Three changes make this reachable:

  • unittest.TestResult has now a verbosity attribute, which it accepted but ignored. TextTestRunner.run() sets it, next to failfast, buffer and tb_locals, because a result class is free to filter what its constructor gets: test.libregrtest does.
  • The unittest -v option is now counted, so that -vv means 3. It is parsed into the TestProgram, whose verbosity is already 1, so -v still means 2.
  • The verbosity of regrtest is one less, so it is translated where the test runner is created.
doctest output
regrtest, python -m unittest nothing
regrtest -v, python -m unittest -v the test name, as before
regrtest -vv, python -m unittest -vv every example

A counted option is relative, so -v passed twice now means 3 rather than 2, and -q -v means 1 rather than 2.

This is the only goal of the issue which is left: the quiet levels already behave as it asks, and GH-134890 made every example a subtest.

  • Issue: Better integration of doctest with unittest and libregrtest #108885

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka @claude
pythongh-108885: Report the examples of a doctest run by unittest
5698da1
DocTestCase ran its examples with verbose=False, so there was no way to ask
unittest for the details which doctest reports on its own.  It now takes the
verbosity from the test result, and reports every example if the test runner
is asked for more than the test names.  They are written to the stream of the
test runner, so that they are not lost when it buffers the output of the test.

To make this reachable:

* unittest.TestResult has now a verbosity attribute, which it accepted but
  ignored.  The test runner sets it, because a result class is free to filter
  what its constructor gets.
* The unittest -v option is now counted, so that -vv means 3.
* The verbosity of regrtest is one less, so it is translated where the test
  runner is created: -v reports the test names, as before, and -vv reports
  also the examples.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 8, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Aug 8, 2026
Better integration of doctest with unittest and libregrtest #108885
Closed
@serhiy-storchaka serhiy-storchaka added stdlib Standard Library Python modules in the Lib/ directory tests Tests in the Lib/test dir labels Aug 8, 2026
@read-the-docs-community

read-the-docs-community Bot commented Aug 8, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33972298 | 📁 Comparing 5698da1 against main (8ed1479)

  🔍 Preview build  

4 files changed
± library/doctest.html
± library/test.html
± library/unittest.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
serhiy-storchaka merged commit 55eef52 into python:main Aug 29, 2026
65 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Aug 29, 2026
@serhiy-storchaka
serhiy-storchaka deleted the doctest-verbosity branch August 29, 2026 19:27
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@serhiy-storchaka @claude @clin1234
pythongh-108885: Report the examples of a doctest run by unittest (py…
0bab24b
…thonGH-155377)

DocTestCase ran its examples with verbose=False, so there was no way to ask
unittest for the details which doctest reports on its own.  It now takes the
verbosity from the test result, and reports every example if the test runner
is asked for more than the test names.  They are written to the stream of the
test runner, so that they are not lost when it buffers the output of the test.

To make this reachable:

* unittest.TestResult has now a verbosity attribute, which it accepted but
  ignored.  The test runner sets it, because a result class is free to filter
  what its constructor gets.
* The unittest -v option is now counted, so that -vv means 3.
* The verbosity of regrtest is one less, so it is translated where the test
  runner is created: -v reports the test names, as before, and -vv reports
  also the examples.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stdlib Standard Library Python modules in the Lib/ directory tests Tests in the Lib/test dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@serhiy-storchaka
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.