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: Use subtests for doctest examples run by unittest by serhiy-storchaka · Pull Request #134890 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented May 29, 2025 •
edited by github-actions Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Run each example as a subtest in unit tests synthesized by doctest.DocFileSuite() and doctest.DocTestSuite().

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

📚 Documentation preview 📚: https://cpython-previews--134890.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka
serhiy-storchaka requested review from iritkatriel and sobolevn May 29, 2025 14:44
@bedevere-app bedevere-app Bot added the awaiting core review label May 29, 2025
@bedevere-app bedevere-app Bot mentioned this pull request May 29, 2025
Better integration of doctest with unittest and libregrtest #108885
Closed
iritkatriel
iritkatriel reviewed May 29, 2025
View reviewed changes
Comment thread Lib/doctest.py Outdated
Comment on lines +1409 to +1411
except:
exception = sys.exc_info()
exc_info = sys.exc_info()
exc_info = (*exc_info[:2], exc_info[2].tb_next)

@iritkatriel iritkatriel May 29, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We don't need to use sys here:

except BaseException as e:
    exc_info = type(e), e, e.__traceback__.tb_next

Sorry, something went wrong.

Uh oh!

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

All reactions

@iritkatriel iritkatriel May 29, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Alternatively, save just the exception here and access its parts below where you need them.

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka May 29, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It does not work, because a traceback here is a not a real traceback. You cannot set it as the part of the exception. Fortunately, all traceback formatting functions and TestCase.addSubTest() work with the exc_info triple.

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka May 29, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Well, here it is a real traceback, but in other place we use a mock traceback, so it is easier to use the same pattern here.

Sorry, something went wrong.

Uh oh!

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

All reactions

@iritkatriel iritkatriel May 29, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, I meant that you extract it from the exception object when you need it below (in this function) and pass that to the internal functions that want the triplet. Just get it from the exception and not from sys.exc_info(). It's the same thing.

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka May 29, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This line is actually a part of #134858.

Sorry, something went wrong.

Uh oh!

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

iritkatriel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@serhiy-storchaka serhiy-storchaka May 29, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I applied your suggestion there.

Sorry, something went wrong.

Uh oh!

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

All reactions
iritkatriel
iritkatriel approved these changes May 29, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels May 29, 2025
@serhiy-storchaka
pythongh-108885: Use subtests for doctest examples run by unittest
55da0a1
Run each example as a subtest in unit tests synthesized by
doctest.DocFileSuite() and doctest.DocTestSuite().
@serhiy-storchaka
serhiy-storchaka force-pushed the doctest-subTest branch from 46860db to 55da0a1 Compare May 29, 2025 21:37
@serhiy-storchaka

serhiy-storchaka commented May 29, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

Before merging this PR I am going to create and merge a PR for documentation fixes, because the current documentation has some errors.

All reactions

Sorry, something went wrong.

Uh oh!

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

serhiy-storchaka added 2 commits May 31, 2025 12:09
@serhiy-storchaka
Merge branch 'main' into doctest-subTest
1ac3dfe
@serhiy-storchaka
Add report_skip() in a NEWS entry.
c7bd9d5
@serhiy-storchaka
serhiy-storchaka merged commit ad39f01 into python:main May 31, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label May 31, 2025
@serhiy-storchaka
serhiy-storchaka deleted the doctest-subTest branch May 31, 2025 10:01
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
@serhiy-storchaka @Pranjal095
pythongh-108885: Use subtests for doctest examples run by unittest (p…
21a272f
…ythonGH-134890)

Run each example as a subtest in unit tests synthesized by
doctest.DocFileSuite() and doctest.DocTestSuite().

Add the doctest.DocTestRunner.report_skip() method.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@serhiy-storchaka @taegyunkim
pythongh-108885: Use subtests for doctest examples run by unittest (p…
8b2ec20
…ythonGH-134890)

Run each example as a subtest in unit tests synthesized by
doctest.DocFileSuite() and doctest.DocTestSuite().

Add the doctest.DocTestRunner.report_skip() method.
@frenzymadness frenzymadness mentioned this pull request Apr 1, 2026
#12645 Fix Python 3.15 compatibility issues in trial twisted/twisted#12602
Open
@serhiy-storchaka serhiy-storchaka mentioned this pull request Aug 8, 2026
gh-108885: Report the examples of a doctest run by unittest #155377
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iritkatriel iritkatriel iritkatriel approved these changes
@sobolevn sobolevn Awaiting requested review from sobolevn

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

2 participants

@serhiy-storchaka @iritkatriel
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 01402503 — 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.