import pytest
from retry_decorator import retry
def test_retry_no_exception_raised():
@retry( Exception , tries = 4 )
def test_success( text ):
return text
assert test_success( 'success' ) == 'success'
def test_no_retry_required():
@retry( Exception , tries = 2 )
def succeeds( counter ):
counter += 1
return counter
assert( succeeds( 0 ), 1)
def test_retry_with_exception():
@retry( Exception , tries = 2 )
def test_fail( text ):
raise Exception( text )
with pytest.raises( Exception ):
test_fail( 'fail' )
# - - - - - NOT SURE IF THIS IS WORKING - - - - - -
def test_no_retry_required_class():
class mycount:
counter = 0
def __init__( self , counter ):
self.counter = counter
@retry( Exception , tries = 2 )
def succeeds( self ):
self.counter += 1
tester = mycount( 0 )
tester.succeeds()
assert( tester.counter , 1)
"""
def test_raise_unexpected_error():
@retry( IOError , tries = 2 )
def raise_unexpected_error():
raise AssertionError( 'AssertionError not retried' )
with pytest.raises( AssertionError ):
raise_unexpected_error()
"""
"""
def test_retry_once_class():
class mycount:
counter = 0
def __init__( self , counter ):
self.counter = counter
@retry( Exception , tries = 2 )
def succeeds( self ):
self.counter += 1
raise Exception( 'failed' )
tester = mycount( 0 )
try:
tester.succeeds()
except Exception as error:
pass
assert( tester.counter , None )
assert( tester.counter , 0 ) # why do all of these asserts pass?
assert( tester.counter , 1 )
"""