-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
mbeliaev/patcher #500
mbeliaev/patcher #500
Conversation
Codecov Report
@@ Coverage Diff @@
## master #500 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 2162 2178 +16
=========================================
+ Hits 2162 2178 +16
Continue to review full report at Codecov.
|
responses/__init__.py
Outdated
@@ -809,11 +810,16 @@ def start(self): | |||
def unbound_on_send(adapter, request, *a, **kwargs): | |||
return self._on_request(adapter, request, *a, **kwargs) | |||
|
|||
self._patcher = std_mock.patch(target=self.target, new=unbound_on_send) | |||
self._patcher.start() | |||
if not self._patcher: |
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.
Should the function on line 810 only be defined when we're creating a patcher as well?
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.
confirm, let's save some runtime on it and just return if patcher already exists
Wow, thanks for fixing this 🥳 |
Closes #481
that was a tricky one, after research I found the root cause. Since default decorator always uses
mock = _default_mock
, when we apply double patching, we override the value of the_patcher
. When standard pythonmock
is trying to stop the patcher, it fails, since we have another object in the memory.Keeping only single
mock
for all nested functions is sufficient enough. Thus, prevent from override and do clean up on the__exit__
.