-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
AsyncMock child mocks should detect their type #82344
Comments
We want child mocks to match their "type" (async or sync). Ex: class Prod:
async def foo():
pass
def bar():
pass
a_mock = AsyncMock(Prod)
isinstance(a_mock.foo(), AsyncMock) == True
isinstance(a_mock.bar(), MagicMock) == True Also this should include magic methods: int(a_mock) should work and return 1 like MagicMocks do. |
This should be simple to do, after #16060 we can add: elif self._mock_methods and _new_name in self._mock_methods: to _get_child_mocks and test with: def test_normal_methods_on_class(self): This might be starting to make _get_child_mocks too complicated, and no longer follows the default "child mocks are the same as their parent". I am not sure how to redefine _get_child_mocks without needing to double up a lot of code to support MagicMocks having AsyncMock child_mocks as well. |
Lately I have been having my doubts around having MagicMocks also create AsyncMocks as children. Should a MagicMock really have a __aenter__ magic method? It makes the using the mocks easier, since you can just use MagicMock or AsyncMock for whatever you are doing and not think about when to use which. But it also might make the code more confusing, since it isn't as clear when to use one or the other. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: