#NEWLINE# def test_retry( ) : #NEWLINE# #INDENT# s = Scraper ( retry_attempts = 3 , retry_wait_seconds = 0.001 , raise_errors = False ) #NEWLINE# mock_request = mock . Mock ( side_effect = [ FakeResponse ( 'http://dummy/' , 500 , 'failure!' ) , FakeResponse ( 'http://dummy/' , 200 , 'success!' ) ] ) #NEWLINE# with mock . patch . object ( requests . Session , 'request' , mock_request ) : #NEWLINE# #INDENT# resp = s . get ( 'http://dummy/' ) #NEWLINE# #UNINDENT# assert ( mock_request . call_count == 2 ) #NEWLINE# mock_request = mock . Mock ( return_value = FakeResponse ( 'http://dummy/' , 500 , 'failure!' ) ) #NEWLINE# with mock . patch . object ( requests . Session , 'request' , mock_request ) : #NEWLINE# #INDENT# resp = s . get ( 'http://dummy/' ) #NEWLINE# #UNINDENT# assert ( resp . status_code == 500 ) #NEWLINE# assert ( mock_request . call_count == 4 )