Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-117364: Add doctest.SkipTest to skip all or some doctest examples #122935

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Aug 12, 2024

I ended up with an exception instead of a decorator. Several reasons:

  1. Exception allows skipping some parts of doctest, giving more flexibility:
>>> 'is not ' + 'skipped'
'is not skipped'

>>> import doctest
>>> raise doctest.SkipTest("All examples after are skipped")

>>> 'skipped'
'not checked'
  1. It will work with testsource and other text-based features. While @skip_if decorator required real objects with attributes.
  2. The API change is simplier with an exception. It only adds one new object. While decorator required a lot of new parameters in existing functions.

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

@sobolevn
Copy link
Member Author

@serhiy-storchaka friendly ping :)

@serhiy-storchaka
Copy link
Member

Thank you for the reminder @sobolevn.

I worked on better integration of doctests with unittests (#108885). In these plans every doctest example is counted as a subtest. Raising unittest.SkipTest only skips a single subtest, not all following subtests. This difference between unittest.SkipTest and doctest.SkipTest may be confusing. On other hand, raising unittest.SkipTest outside of a subTest() block skips the whole test. Since the line that raises doctest.SkipTest does not have an expected output or traceback, it may be not counted as example.

So I want to try to make more progress on that issue first. Than we will see how it works together and what API is better for skipping doctests.

@sobolevn
Copy link
Member Author

Thanks for the info, would love to see better unittest + doctest intergration. Marking this as a draft for now.

@sobolevn sobolevn marked this pull request as draft October 19, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants