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 — bpo-17013: Extend Mock.called to allow waiting for calls by Kentzo · Pull Request #17133 · python/cpython

Conversation

@Kentzo

@Kentzo Kentzo commented Nov 12, 2019 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This implementation of bpo-17013 is alternative to #16094

Changes are based on my work for asynctest. Specifically on _AwaitEvent that was left out when related code was ported to CPython.

Key features:

  • Gives meaning to the existing Mock.called property, otherwise not much useful
  • Does not require end users to do anything: change is automatically available in every Mock
  • Utilizes existing semantics of python conditionals (both asyncio and threading)

Accepting this change will allow me to port _AwaitEvent therefore giving identical semantics to both wait-for-calls and wait-for-awaits.

I will provide necessary typing annotations for typeshed.

Considerations:

  1. This approach changes type of the Mock.called property from bool to private bool-like _CallEvent. However, the only practical problem I could think of is if someone was checking type of Mock.called (e.g. via isinstance). That does not sound like a plausible problem: after all the property itself is seldom used with exception of conditional expressions where _CallEvent.__bool__ and _CallEvent.__eq__ is sufficient.
  2. It probably makes sense to provide convenience methods like wait_for_call, but I would like to hear the opinion of the reviewers.

CC: @vstinner @tirkarthi @mariocj89

https://bugs.python.org/issue17013

Sorry, something went wrong.

Uh oh!

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

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Nov 12, 2019
@bedevere-bot bedevere-bot added the awaiting review label Nov 12, 2019
@Kentzo Kentzo mentioned this pull request Nov 13, 2019
Integrating with Python 3.8 Martiusweb/asynctest#144
Open
@Kentzo
Kentzo force-pushed the bpo-17013 branch from 7c8ebff to eb981b4 Compare November 13, 2019 22:12
@Kentzo
Kentzo requested review from 1st1 and asvetlov as code owners November 13, 2019 22:12
@Kentzo
Kentzo force-pushed the bpo-17013 branch 2 times, most recently from 1c9de24 to fbe5422 Compare November 13, 2019 22:56
@Kentzo

Kentzo commented Nov 13, 2019

Copy link
Copy Markdown
Contributor Author

Probably one method that the object should definitely have is wait_for_call(self, call, /, skip=0, timeout=None).

All reactions

Sorry, something went wrong.

Uh oh!

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

@Kentzo
Kentzo force-pushed the bpo-17013 branch 3 times, most recently from 54b7b06 to c740cb8 Compare November 14, 2019 07:26
@Kentzo
bpo-17013: Extend Mock.called to allow waiting for calls
eab4041
New methods allow tests to wait for calls executing in other threads.
@Kentzo
Kentzo force-pushed the bpo-17013 branch from c740cb8 to eab4041 Compare November 14, 2019 16:56
@mariocj89

mariocj89 commented Nov 17, 2019

Copy link
Copy Markdown
Contributor

Thanks @Kentzo for putting this through. From conversations with @voidspace, @lisroach, @tirkarthi and in the issue tracker it seems that people wanted to go with having a different mock just for this use case, rather than trying to fold it into the existing one. Similar to what was done with AsyncMock.

Happy to re-evaluate it, but I guess that should be a conversation in the issue tracker.

lisroach 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.

@cjw296

cjw296 commented Jan 24, 2020

Copy link
Copy Markdown
Contributor

Closing this PR for now, as it looks like @mariocj89 will be putting in another PR to take over from this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@cjw296 cjw296 closed this Jan 24, 2020
@Kentzo

Kentzo commented Jan 28, 2020

Copy link
Copy Markdown
Contributor Author

@cjw296 Hmm, where was that discussion?

All reactions

Sorry, something went wrong.

Uh oh!

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

@cjw296

cjw296 commented Jan 28, 2020

Copy link
Copy Markdown
Contributor

https://bugs.python.org/issue17013#msg352211
#16094

Looks like @mariocj89 's PR actually predates this one, I don't have a strong opinion on either, so happy to re-open this PR if you, @mariocj89, @tirkarthi, @voidspace and @lisroach want to discuss which PR to take forward.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mariocj89

mariocj89 commented Jan 28, 2020

Copy link
Copy Markdown
Contributor

Hi @Kentzo, this was initially discussed in https://bugs.python.org/issue17013#msg352211 and offlne in the core dev sprints with @voidspace, @lisroach and @tirkarthi when we put forward the other PR. @voidspace preferred to go down the path of having specialized mocks rather than having a mock have all the functionality. Similar to the asyncmock.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Kentzo

Kentzo commented Jan 29, 2020

Copy link
Copy Markdown
Contributor Author

At some point I was asked to move the discussion to bugs.python. For the benefit of the future developers I believe it makes sense to point out the benefits of the new "class approach" there as well.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mariocj89

mariocj89 commented Jan 29, 2020

Copy link
Copy Markdown
Contributor

At some point I was asked to move the discussion to bugs.python. For the benefit of the future developers I believe it makes sense to point out the benefits of the new "class approach" there as well.

Absolutely, that's why I suggested that. The issue lays on the availability of committer time though. It might be a busy time right now.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Kentzo

Kentzo commented Apr 27, 2020

Copy link
Copy Markdown
Contributor Author

Added implementation of the wait_for_call convenience method that can be used like this:

mock.method_1.called.wait_for_call(call(1, a=1), timeout=0.01)
All reactions

Sorry, something went wrong.

Uh oh!

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

@Kentzo Kentzo mentioned this pull request Apr 27, 2020
gh-61215: New mock to wait for multi-threaded events to happen #16094
Merged
@cjw296

cjw296 commented Apr 27, 2020

Copy link
Copy Markdown
Contributor

@Kentzo - it's unclear where you've added this?

All reactions

Sorry, something went wrong.

Uh oh!

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

@Kentzo

Kentzo commented Apr 27, 2020

Copy link
Copy Markdown
Contributor Author

I guess PR is not updated because it's closed. The corresponding branch in my repo got updated.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Kentzo

Kentzo commented Jun 7, 2020

Copy link
Copy Markdown
Contributor Author

Any chance for this PR to get reviewed?

All reactions

Sorry, something went wrong.

Uh oh!

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

@cjw296

cjw296 commented Jun 8, 2020

Copy link
Copy Markdown
Contributor

Doesn't look like I can re-open this PR, so please submit a new one if you want anything reviewed. Please comment here with a link to the new one.

@mariocj89 - where did you get to with your approach?

All reactions

Sorry, something went wrong.

Uh oh!

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

@mariocj89

mariocj89 commented Jun 9, 2020

Copy link
Copy Markdown
Contributor

There is an open PR that was reviewed but never re-reviewed after proposed changes here: #16094

cjw296 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.

@Kentzo

Kentzo commented Jun 9, 2020 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

@cjw296 #20759

All reactions

Sorry, something went wrong.

Uh oh!

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

@Kentzo

Kentzo commented Oct 21, 2020

Copy link
Copy Markdown
Contributor Author

Just noticed that I put wrong link above 🤦🏻‍♂️, fixed the comment.

All reactions

Sorry, something went wrong.

Uh oh!

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

@pitrou pitrou mentioned this pull request Apr 10, 2022
Allow waiting on a mock #61215
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@1st1 1st1 Awaiting requested review from 1st1
@asvetlov asvetlov Awaiting requested review from asvetlov

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

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.

5 participants

@Kentzo @mariocj89 @cjw296 @the-knights-who-say-ni @bedevere-bot
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.