Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-108885: Use subtests for doctest examples run by unittest#134890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Lib/doctest.py Outdated
except: | ||
exception = sys.exc_info() | ||
exc_info = sys.exc_info() | ||
exc_info = (*exc_info[:2], exc_info[2].tb_next) |
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
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.
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.
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.
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.
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.
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.
Run each example as a subtest in unit tests synthesized bydoctest.DocFileSuite() and doctest.DocTestSuite().
46860db
to55da0a1
CompareBefore merging this PR I am going to create a merge PR for documentation fixes, because the current documentation has some errors. |
Uh oh!
There was an error while loading.Please reload this page.
Run each example as a subtest in unit tests synthesized by doctest.DocFileSuite() and doctest.DocTestSuite().
📚 Documentation preview 📚:https://cpython-previews--134890.org.readthedocs.build/