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-116622: Enable `test_doctest` on platforms that don't support subprocesses by mhsmith · Pull Request #116758 · python/cpython

Conversation

@mhsmith

@mhsmith mhsmith commented Mar 13, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

When testing on Android I noticed that test_doctest and test_zipimport_support (which calls test_doctest) were skipping entire modules because of missing subprocess support, even though only one test method actually required subprocesses. This PR makes the skip more selective.

  • Issue: Add support for Android as a target platform #116622

Sorry, something went wrong.

Uh oh!

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

All reactions
@mhsmith
Enable test_doctest on platforms that don't support subprocesses
4264ca9
@bedevere-app bedevere-app Bot added the awaiting review label Mar 13, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Mar 13, 2024
Add support for Android as a target platform #116622
Closed
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Mar 13, 2024
@mhsmith
Fix whitespace
7d4f0fb
@mhsmith

mhsmith commented Mar 21, 2024

Copy link
Copy Markdown
Member Author

@sobolevn: You've done some work in this area recently; are you able to review this PR?

There's one test failure, but I don't think it's related.

All reactions

Sorry, something went wrong.

Uh oh!

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

sobolevn
sobolevn reviewed Mar 21, 2024
View reviewed changes

@sobolevn sobolevn left a comment

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.

Thanks, I like the idea, no need to skip the whole module just because one test requires the subprocess module.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_doctest/test_doctest.py Outdated
Traceback (most recent call last):
...
FileNotFoundError: [Errno ...] ...nosuchfile...
if support.has_subprocess_support:

@sobolevn sobolevn Mar 21, 2024

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.

What I don't like is that the diff is huge. Maybe we can do something like

def doctest_requires_subproccess(func):
    if not support.has_subprocess_support:
        func.__doc__ = None  # skip the doctest by setting it to `None`
    return func

@doctest_requires_subprocess
def test_CLI():  # as before, no changes
    ...

I've tried this locally with if True:

» ./python.exe -m test test_doctest -m test_CLI
Using random seed: 4265888589
0:00:00 load avg: 2.23 Run 1 test sequentially
0:00:00 load avg: 2.23 [1/1] test_doctest
test_doctest ran no tests

== Tests result: NO TESTS RAN ==

1 test run no tests:
    test_doctest

Total duration: 59 ms
Total tests: run=0 (filtered)
Total test files: run=1/1 (filtered) run_no_tests=1
Result: NO TESTS RAN

Sorry, something went wrong.

Uh oh!

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

All reactions

@mhsmith mhsmith Mar 21, 2024

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.

Good idea; I've generalized it slightly so it can accept any skip condition.

Sorry, something went wrong.

Uh oh!

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

All reactions
@mhsmith mhsmith added the skip news label Mar 21, 2024
mhsmith added 2 commits March 21, 2024 18:37
@mhsmith
Merge branch 'main' into doctest-subprocess
b735bd7
@mhsmith
Switch to a doctest_skip_if decorator
ffee805
sobolevn
sobolevn approved these changes Mar 21, 2024
View reviewed changes
@sobolevn

sobolevn commented Mar 21, 2024

Copy link
Copy Markdown
Member

I want to double check our idea, maybe with @serhiy-storchaka ?
I know that you are also interested in doctest module and its tests.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
serhiy-storchaka self-requested a review March 21, 2024 21:19
serhiy-storchaka
serhiy-storchaka reviewed Mar 21, 2024
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

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.

There is one minor problem -- a skipped test just disappears from the output. It is not counted as skipped.

Sorry, something went wrong.

Uh oh!

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

All reactions
@sobolevn

sobolevn commented Mar 22, 2024

Copy link
Copy Markdown
Member

Yes, but I don't think that there's an easy way to fix that. Since the whole module is counted as a single DocTestSuite, we can see how it behaves with other skips (with -OO for example):

» ./python.exe -OO -m test test_doctest            
Using random seed: 1564874428
0:00:00 load avg: 2.01 Run 1 test sequentially
0:00:00 load avg: 2.01 [1/1] test_doctest

== Tests result: SUCCESS ==

1 test OK.

Total duration: 246 ms
Total tests: run=10 skipped=1
Total test files: run=1/1
Result: SUCCESS

Only 1 is reported to be skipped, while in reality all doctests were skipped in this module.

So, not reporting a single doctest is in line with that.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented Mar 22, 2024

Copy link
Copy Markdown
Member

It is far from ideal, but we can set a docstring with a skipped doctest instead of None.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mhsmith
Make DocTestCase report as skipped if all examples in the doctest are…
d022538
… skipped
@mhsmith

mhsmith commented Mar 27, 2024

Copy link
Copy Markdown
Member Author

In the current state a skipped doctest still isn't counted as skipped by unittest – it just shows as a passed test, even in the verbose log. So I've made a small change to DocTestCase to improve that.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mhsmith mhsmith removed the skip news label Mar 27, 2024
@sobolevn

sobolevn commented Mar 27, 2024

Copy link
Copy Markdown
Member

I think that you are fixing this in the wrong PR :)
Please, create a new issue and a new PR about doctest skip feature.

And you can keep this PR focused on just doctest + subprocess behavior.

All reactions

Sorry, something went wrong.

Uh oh!

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

serhiy-storchaka
serhiy-storchaka approved these changes Mar 27, 2024
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment •
edited
Loading

Uh oh!

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

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.

LGTM.

Although I agree that the change in DocTestCase deserves a separate issue or at least a separate PR (you can also make it a part of the larger issue #108885). It is larger and more interesting than your initial PR. But anyway, both changes LGTM.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Mar 27, 2024
sobolevn
sobolevn reviewed Mar 27, 2024
View reviewed changes

@sobolevn sobolevn left a comment

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.

I also think that we can add @doctest_skip and @doctest_skip_if decorators to the stdlib. They might be useful for others. This should be a new issue as well :)

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_doctest/sample_doctest_skip.py Resolved

Uh oh!

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

@mhsmith mhsmith mentioned this pull request Mar 27, 2024
gh-117294: Report DocTestCase as skipped if all examples in the doctest are skipped #117297
Merged
@mhsmith
Move most of previous commit into python#117297
405d679
@mhsmith mhsmith added the skip news label Mar 27, 2024
@mhsmith

mhsmith commented Mar 27, 2024

Copy link
Copy Markdown
Member Author

I agree that the change in DocTestCase deserves a separate issue or at least a separate PR

OK, I've split it out into #117297.

I also think that we can add @doctest_skip and @doctest_skip_if decorators to the stdlib. They might be useful for others.

I looked into allowing doctests to use the existing unittest.skip decorators, but that isn't so easy, because by the time we come to run the test, we no longer have a reference to the function whose docstring it came from.

Anyway, I've already got way deeper into this area than I was planning, so I'll leave that to someone else. 😄

All reactions

Sorry, something went wrong.

Uh oh!

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

@sobolevn

sobolevn commented Mar 27, 2024

Copy link
Copy Markdown
Member

than I was planning, so I'll leave that to someone else.

I will take it from here, thank you for this PR! 👍

All reactions

Sorry, something went wrong.

Uh oh!

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

sobolevn
sobolevn reviewed Mar 29, 2024
View reviewed changes

@sobolevn sobolevn left a comment

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.

Thanks! Just one comment.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_doctest/test_doctest.py Resolved

Uh oh!

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

@sobolevn sobolevn mentioned this pull request Mar 29, 2024
Consider adding doctest.skip_if decorator #117364
Open
@mhsmith @sobolevn
Don't modify docstrings when running in optimized mode
f9e9687
Co-authored-by: Nikita Sobolev <[email protected]>
sobolevn
sobolevn approved these changes Mar 31, 2024
View reviewed changes
@mhsmith

mhsmith commented Apr 4, 2024

Copy link
Copy Markdown
Member Author

@sobolevn: Are you able to merge this PR?

All reactions

Sorry, something went wrong.

Uh oh!

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

@sobolevn

sobolevn commented Apr 9, 2024

Copy link
Copy Markdown
Member

Yes, sure! Thanks a lot for working on this 👍

All reactions

Sorry, something went wrong.

Uh oh!

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

@sobolevn
sobolevn merged commit 22b25d1 into python:main Apr 9, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 9, 2024
@sobolevn

sobolevn commented Apr 9, 2024

Copy link
Copy Markdown
Member

What do you think about 3.12 backport?

All reactions

Sorry, something went wrong.

Uh oh!

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

@mhsmith

mhsmith commented Apr 9, 2024

Copy link
Copy Markdown
Member Author

On 3.12 the only platforms that don't support subprocesses are Emscripten and WASI, so a backport would slightly improve test coverage for them.

However, to actually report the test as skipped would require #117297, which shouldn't be backported because it's a behavior change.

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

Sorry, something went wrong.

Uh oh!

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

@sobolevn sobolevn mentioned this pull request Apr 10, 2024
[3.12] gh-117692: Fix AttributeError in DocTestFinder on wrapped builtin_or_method (GH-117699) #117708
Merged
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
@mhsmith @sobolevn @diegorusso
pythongh-116622: Enable test_doctest on platforms that don't suppor…
c94ff86
…t subprocesses (python#116758)

Co-authored-by: Nikita Sobolev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@sobolevn sobolevn sobolevn approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

skip news 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.

3 participants

@mhsmith @sobolevn @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 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.