-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Make spy a context manager #118
Comments
Hi @neumond, Thanks for taking the time to write your suggestions! Also appreciate the easy to follow examples. Unfortunately none of the suggestions can be implemented without breaking the current interface, so we might need a new method name that returns an object that:
Do you have any suggestions? cc @fogo, which contributed |
Hello there, just found this randomly while looking for some sort of "spy as context manager" feature. Though what naively imagined would be more like : def test_context_mgr(mocker):
o = SomeClass()
with mocker.spy(SomeClass, 'method', call_count=1):
o.facade()
o.facade() (not necessarily using The motivation would be to have something similar to |
I run into a similar need of capturing return values from the object spied upon. My solution was a wrapper around If we can agree on what the solution should roughly look like,I can try writing up a PR. |
Didn't notice that you already implemented this with 1.11. Please disregard my comment. Awesome work by the way :) |
@Mark90 indeed the issue was a bit confusing, thanks for bringing this to attention. I've updated the title and mentioned that the return value has been implemented in 1.11. 👍 |
Capture return value
NOTE: already implemented in 1.11
Spy as context manager
That's probably kind of misusing mocker object, but in my case there's a quite long test and I want to restrict fragment of code where particular spy object is applied.
Currently I can only find arguments
The text was updated successfully, but these errors were encountered: