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

bpo-38163: Child mocks detect their type as sync or async #16471

Merged
merged 6 commits into from
Sep 30, 2019

Conversation

lisroach
Copy link
Contributor

@lisroach lisroach commented Sep 29, 2019

This should be the last diff to get the child mocks detecting their type as either synchronous or asynchronous and returning AsyncMock or MagicMock (or Mock) depending on their type.

The main goal is for classes that have a mix of asynchronous and synchronous methods to auto-detect whether they should be AsyncMock or a synchronous mocks. Example:

  >>> class ExampleClass:
  ...     def sync_foo():
  ...         pass
  ...     async def async_foo():
  ...         pass
  ...
  >>> a_mock = AsyncMock(ExampleClass)
  >>> a_mock.sync_foo
  <MagicMock name='a_mock.sync_foo' id='...'>
  >>> a_mock.async_foo
  <AsyncMock name='a_mock.async_foo' id='...'>
  >>> mock = Mock(ExampleClass)
  >>> mock.sync_foo
  <Mock name='mock.sync_foo' id='...'>
  >>> mock.async_foo
  <AsyncMock name='mock.async_foo' id='...'>

This defies Mock's typical functionality where all child mocks follow the type of their parent mock, but after some discussion I believe the auto-detection is more important to the typical user than a consistency with current Mock style.

https://bugs.python.org/issue38163

@lisroach lisroach merged commit 3667e1e into python:master Sep 30, 2019
@lisroach lisroach deleted the issue38163 branch September 30, 2019 04:56
@miss-islington
Copy link
Contributor

Thanks @lisroach for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

I'm having trouble backporting to 3.8. Reason: 'Error 110 while writing to socket. Connection timed out.'. Please retry by removing and re-adding the needs backport to 3.8 label.

@lisroach lisroach added needs backport to 3.8 only security fixes and removed needs backport to 3.8 only security fixes labels Sep 30, 2019
@miss-islington
Copy link
Contributor

Thanks @lisroach for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @lisroach, I had trouble checking out the 3.8 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 3667e1ee6c90e6d3b6a745cd590ece87118f81ad 3.8

lisroach added a commit to lisroach/cpython that referenced this pull request Sep 30, 2019
…onGH-16471)

(cherry picked from commit 3667e1e)

Co-authored-by: Lisa Roach <lisaroach14@gmail.com>
@bedevere-bot
Copy link

GH-16484 is a backport of this pull request to the 3.8 branch.

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.

4 participants