-
Notifications
You must be signed in to change notification settings - Fork 91
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
Using Patcher with py.test #135
Comments
Thanks - this sounds good! A context manager for Patcher certainly makes sense in this context. I may add this tomorrow - as it's a small addition, I think a PR is not really needed. |
Oh fantastic, I was hoping you'd say that. ;) On Thu, Nov 17, 2016 at 9:53 PM mrbean-bremen [email protected]
|
- proposed by @mirosval in pytest-dev#135
Neither I nor @jmcgeheeiv have much experience with pytest, so we are always glad to get input from pytest users. Thanks for the contribution! |
Yes, this is exactly what I did on my side. Perfect! Thank you so much! |
I have run into an issue using
Patcher
with py.test.The issue is that when the code under test throws, the exception bubbles up to
py.test
, which will then fail processing it, becauseos.path
is patched.This then results into a horrible mess of tracebacks and exceptions during handling of other exceptions and the original exception is lost, so it makes debugging the underlying problem difficult.
Example:
I fixed this by wrapping
Patcher
in a context manager like so:This ensures that when an exception is thrown, the patch is unapplied on exit from the context block and the exception is allowed to correctly bubble up and be caught by
py.test
.I would suggest adding the two context methods to the original
Patcher
. I could make a PR for this if you like.The text was updated successfully, but these errors were encountered: