Fix RuntimeError if user code calls patcher.stopall#138
Fix RuntimeError if user code calls patcher.stopall#138nicoddemus merged 1 commit intopytest-dev:masterfrom
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.
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.
This might be a separate issue. It's possible to get into this situation as-is.
There was a problem hiding this comment.
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