#NEWLINE# def test_timeout_retry( ) : #NEWLINE# #INDENT# count = [ ] #NEWLINE# def side_effect( * args , **kwargs ) : #NEWLINE# #INDENT# if count : #NEWLINE# #INDENT# return FakeResponse ( 'http://dummy/' , 200 , 'success!' ) #NEWLINE# #UNINDENT# count . append ( 1 ) #NEWLINE# raise requests . Timeout ( 'timed out :(' ) #NEWLINE# #UNINDENT# mock_request = mock . Mock ( side_effect = side_effect ) #NEWLINE# s = Scraper ( retry_attempts = 0 , retry_wait_seconds = 0.001 ) #NEWLINE# with mock . patch . object ( requests . Session , 'request' , mock_request ) : #NEWLINE# #INDENT# pytest . raises ( requests . Timeout , s . get , 'http://dummy/' ) #NEWLINE# assert ( mock_request . call_count == 1 ) #NEWLINE# #UNINDENT# mock_request . reset_mock ( ) #NEWLINE# count = [ ] #NEWLINE# s = Scraper ( retry_attempts = 2 , retry_wait_seconds = 0.001 ) #NEWLINE# with mock . patch . object ( requests . Session , 'request' , mock_request ) : #NEWLINE# #INDENT# resp = s . get ( 'http://dummy/' ) #NEWLINE# assert ( resp . content == 'success!' ) #NEWLINE# assert ( mock_request . call_count == 2 )