-
-
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
Fix RuntimeError if user code calls patcher.stopall #138
Conversation
Hmm, from #137 (comment) it sounds like it would be better if pytest-mock's mocks could be excluded? But that's maybe a) not trivial, and b) not good in general - likely you should not call |
fc83682
to
24bce30
Compare
Agree, unfortunately there's no public API to check for that; |
if text_type(e) == "stop called on unstarted patcher": | ||
pass | ||
else: | ||
raise |
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.
Thanks heaps for this, but I'm concerned that this might obfuscate other errors.
What would happen if some test called .stopall()
, then some other test which relied on pytest-mock's internal mocks was called. Would it be clear what was going on?
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.
This might be a separate issue. It's possible to get into this situation as-is.
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.
Thanks for the review!
I don't think so, as we are not catching any RuntimeError, we only ignore the very specific message... as I commented above, I think this is safe, but might break in future mock releases if they ever change the message. We should also switch to a public API that allows us to check if a patcher has already been stopped, if one is ever introduced.
Just to add to this the |
Thanks @tirkarthi for the pointer, created #147 to track it. 👍 |
Fix #137