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-70280: allow using custom sys.displayhook's with doctest #25651

Closed
wants to merge 1 commit into from
Closed

gh-70280: allow using custom sys.displayhook's with doctest #25651

wants to merge 1 commit into from

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Apr 27, 2021

@skirpichev
Copy link
Member Author

test_ttk_guionly() failure unrelated to the PR.

@skirpichev
Copy link
Member Author

skirpichev commented May 17, 2021

@tim-one, you are listed as an expert for this module, thus I'm ask you for review. The author of the reverted patch is ok with the change, see the bug thread. I think, it's an easy thing to decide if this can be accepted or not. I would prefer this in 3.10, if possible.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jun 17, 2021
@skirpichev
Copy link
Member Author

@ezio-melotti, you are listed as an expert for testing in the devguide, could you review this little PR? (It seems the doctest module lacks a maintainer.)

Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Choose a reason for hiding this comment

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

Good call.

@erlend-aasland erlend-aasland changed the title bpo-26092: allow using custom sys.displayhook's with doctest gh-70280: allow using custom sys.displayhook's with doctest Jul 21, 2022
@erlend-aasland
Copy link
Contributor

erlend-aasland commented Jul 21, 2022

(FYI, I've updated the PR description with gh numbers iso. bpo numbers.)

@erlend-aasland
Copy link
Contributor

It isn't obviously clear to me if Tim's #70280 (comment) approved or disapproved of this change. I have no opinion about it, but I'd appreciate a +1 from one or two other core devs before accepting this.

Lib/test/test_doctest.py Outdated Show resolved Hide resolved
Comment on lines 1207 to 1214
>>> with patch('sys.displayhook', sys.__displayhook__):
... r = doctest.DocTestRunner(verbose=False).run(test)
Copy link
Member

@ezio-melotti ezio-melotti Aug 5, 2022

Choose a reason for hiding this comment

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

Instead of "fixing" the displayhook here with unittest.mock.patch, the behavior and this workaround should be documented:

  • describe that doctest now honors custom displayhooks
  • add a .. versionchanged to indicate the change in behavior
  • suggest unittest.mock.patch as a way to restore the displayhook while running the doctests
  • suggest testsetup/testcleanup as another option

In addition, since this is a change in behavior, it might be better to add a FutureWarning and actually implement the change after 1-2 releases.

Copy link
Member Author

@skirpichev skirpichev Aug 5, 2022

Choose a reason for hiding this comment

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

@ezio-melotti , I have made the requested changes; please review again.

I'm not so sure which is a right place for the versionchanged stuff. Right now it's the changed method. Let me know it it's ok or suggesting patch/testsetup/etc is required (I find this too trivial to add, after all - changing the sys.displayhook is very well documented).

Let me also know if the two-step process with the FutureWarning is required: I'll create another PR with a warning (actual change will be postponed for 3.13, it's correct?). So far, the current state wasn't documented and it seems to be rather a bug then a compatibility breaker...

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@skirpichev
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ezio-melotti: please review the changes made to this pull request.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Aug 7, 2022
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

It does not add support for testing examples with a customized sys.displayhook value, as claimed. It unconditionally changes the current behavior. It breaks the code that sets sys.displayhook outside of tests, and it leaks sys.displayhook explicitly set in a doctest.

Doc/library/doctest.rst Outdated Show resolved Hide resolved
@skirpichev
Copy link
Member Author

skirpichev commented Aug 7, 2022

It unconditionally changes the current behavior.

@serhiy-storchaka, that's the point.

It breaks the code that sets sys.displayhook outside of tests, and it leaks sys.displayhook explicitly set in a doctest.

In fact, it tests the code that sets sys.displayhook outside of tests, unless I misunderstood you. In last commits I've added also a test for changing the sys.displayhook value inside of doctests.

@skirpichev
Copy link
Member Author

@erlend-aasland, maybe you could redo your review after recent changes? Core devs seems to be inactive for month and I would appreciate any feedback on how well I addressed their review comments.

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Sep 12, 2022

erlend-aasland, maybe you could redo your review after recent changes? Core devs seems to be inactive for month and I would appreciate any feedback on how well I addressed their review comments.

My stance is still the same as before:

It isn't obviously clear to me if Tim's #70280 (comment) approved or disapproved of this change. I have no opinion about it, but I'd appreciate a +1 from one or two other core devs before accepting this.

Although I have the power to approve and merge this, I of course won't do such a thing. I don't see any loud and clear +1 from any other core dev, hence I'm more aligned to close both this PR and the linked issue.

I'll unsubscribe from this and leave it for Ezio and Serhiy (or any other core dev who want to pick this up).

@skirpichev
Copy link
Member Author

Feel free to take this over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants