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
Add mock_async_callable for asyncio support #60
Conversation
"Mocking __new__ is not allowed with mock_callable(), please use " | ||
"mock_constructor()." | ||
) | ||
return _MockAsyncCallableDSL(target, method) |
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.
The logic for __new__
is duplicated, it could be moved to _MockCallableDSL
.
Neat! This seems in a good direction! There are a few things that we need to look over as well:
From the top of my mind, I do expect these to "just work":
But I have my doubts about these:
Unfortunately Python has shown to be full of quicks and exception cases on how things work. The current tests, while hard to maintain and confusing (sorry about that), were extremely helpful in getting all corner cases in the past, we'd loose a lot if we did not have the same coverage for async. Ideally, we'd need to duplicate all sync wyth async equivalents of the tests, but in some cases (eg: iterator, calling original) we'd need more async specific stuff. I'm happy to assist you on that if needed. |
Thanks for the comments @fornellas, I'll update this PR with the requested changes |
@fornellas I'm still working on this, not ready for review yet. Just pushed my changes so far so I don't lose them. |
FYI, #59 should help testing async stuff, I'm still working on it. |
@jivid as we spoke, I'm gonna start working on this issue now so we can deliver it ASAP. I'm closing this PR so we don't clash, but feel free to ping me to join forces if you can spare bandwidth. Thanks for what we have here already, I have something to grow on top :-D |
Add a
mock_async_callable
DSL which works exactly likemock_callable
but forasync
functions.The decision to not patch
mock_callable
to supportasync
functions was intentional and made to make it clear when reading the test what kind of code is being mocked. Just as you can't just stickasync
in front of a function and expect everything to work, you shouldn't rely onmock_callable
just working either.