#NEWLINE# def test_nested_cassettes_with_session_created_before_nesting( scheme , tmpdir ) : #NEWLINE# #INDENT# '\n    This tests ensures that a session that was created while one cassette was\n    active is patched to the use the responses of a second cassette when it\n    is enabled.\n    ' #NEWLINE# url = ( scheme + '://httpbin.org/bytes/1024' ) #NEWLINE# with vcr . use_cassette ( str ( tmpdir . join ( 'first_nested.yaml' ) ) ) : #NEWLINE# #INDENT# session = requests . session ( ) #NEWLINE# first_body = session . get ( url ) . content #NEWLINE# with vcr . use_cassette ( str ( tmpdir . join ( 'second_nested.yaml' ) ) ) : #NEWLINE# #INDENT# second_body = session . get ( url ) . content #NEWLINE# third_body = requests . get ( url ) . content #NEWLINE# #UNINDENT# #UNINDENT# with vcr . use_cassette ( str ( tmpdir . join ( 'second_nested.yaml' ) ) ) : #NEWLINE# #INDENT# session = requests . session ( ) #NEWLINE# assert ( session . get ( url ) . content == second_body ) #NEWLINE# with vcr . use_cassette ( str ( tmpdir . join ( 'first_nested.yaml' ) ) ) : #NEWLINE# #INDENT# assert ( session . get ( url ) . content == first_body ) #NEWLINE# #UNINDENT# assert ( session . get ( url ) . content == third_body ) #NEWLINE# #UNINDENT# session . get ( 'http://www.reddit.com' )