def test_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' with contextlib.ExitStack() as exit_stack: first_cassette = exit_stack.enter_context(Cassette.use(path='test')) exit_stack.enter_context( 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 first with Cassette.use(path='test') as second_cassette: with 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 effect assert_get_response_body_is('first_response')
def test_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" with contextlib.ExitStack() as exit_stack: first_cassette = exit_stack.enter_context(Cassette.use(path="test")) exit_stack.enter_context( 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 first with Cassette.use(path="test") as second_cassette: with 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 effect assert_get_response_body_is("first_response")