gh-108885: Report the examples of a doctest run by unittest - #155377
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-108885: Report the examples of a doctest run by unittest#155377serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
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) <noreply@anthropic.com>
Documentation build overview
4 files changed± library/doctest.html± library/test.html± library/unittest.html± whatsnew/changelog.html |
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.
DocTestCase.runTest()runs the examples withverbose=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.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.TestResulthas now averbosityattribute, which it accepted but ignored.TextTestRunner.run()sets it, next tofailfast,bufferandtb_locals, because a result class is free to filter what its constructor gets:test.libregrtestdoes.unittest-voption is now counted, so that-vvmeans 3. It is parsed into theTestProgram, whose verbosity is already 1, so-vstill means 2.regrtest,python -m unittestregrtest -v,python -m unittest -vregrtest -vv,python -m unittest -vvA counted option is relative, so
-vpassed twice now means 3 rather than 2, and-q -vmeans 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.