You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nesting any use of CassetteContextDecorators will result in complete unpatching after the first context is exited. This is because the reset function in patch.py indiscriminately sets all the patches back to the original state that was found in the module at import time.
Patching is a pretty tricky problem and I think that doing it by hand amounts to reinventing the wheel in some sense. I think that the best way to fix this issue is to rely on the mock library to do all of the patching.
Here are two tests that illustrate the problem:
@mock.patch('vcr.cassette.requests_match', _mock_requests_match)@mock.patch('vcr.cassette.Cassette.can_play_response_for', return_value=True)@mock.patch('vcr.cassette.Cassette._save', return_value=True)deftest_nesting_cassette_context_managers(*args):
first_response= {'body': {'string': b'first_response'}, 'headers': {},
'status': {'message': 'm', 'code': 200}}
second_response=copy.deepcopy(first_response)
second_response['body']['string'] =b'second_response'withCassette.use('test') asfirst_cassette, \
mock.patch.object(first_cassette, 'play_response', return_value=first_response):
assert_get_response_body_is('first_response')
# Make sure a second cassette can supercede the firstwithCassette.use('test') assecond_cassette, \
mock.patch.object(second_cassette, 'play_response', return_value=second_response):
assert_get_response_body_is('second_response')
# Now the first cassette should be back in effectassert_get_response_body_is('first_response')
deftest_nesting_context_managers_by_checking_references_of_http_connection():
withCassette.use('test'):
first_cassette_HTTPConnection=httplib.HTTPConnectionwithCassette.use('test'):
passasserthttplib.HTTPConnectionisfirst_cassette_HTTPConnection
Nesting any use of CassetteContextDecorators will result in complete unpatching after the first context is exited. This is because the reset function in patch.py indiscriminately sets all the patches back to the original state that was found in the module at import time.
Patching is a pretty tricky problem and I think that doing it by hand amounts to reinventing the wheel in some sense. I think that the best way to fix this issue is to rely on the mock library to do all of the patching.
Here are two tests that illustrate the problem:
and here is the output that they produce:
https://gist.github.com/anonymous/f51bdd0334ee5fdb33bc
The text was updated successfully, but these errors were encountered: