Skip to content

Commit

Permalink
Don't fall over if an old version of tornado is installed
Browse files Browse the repository at this point in the history
Related to issue #99 -- even if we don't properly support old versions
of tornado, we can do better than raise an AttributeError if an old
version *just happens* to be installed.
  • Loading branch information
tipabu authored and pastamaker[bot] committed Jan 18, 2018
1 parent 5dd4c19 commit 97cde0d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tenacity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def retry(*dargs, **dkw):
def wrap(f):
if asyncio and asyncio.iscoroutinefunction(f):
r = AsyncRetrying(*dargs, **dkw)
elif tornado and tornado.gen.is_coroutine_function(f):
elif tornado and hasattr(tornado.gen, 'is_coroutine_function') \
and tornado.gen.is_coroutine_function(f):
r = TornadoRetrying(*dargs, **dkw)
else:
r = Retrying(*dargs, **dkw)
Expand Down
13 changes: 13 additions & 0 deletions tenacity/tests/test_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def test_retry(self):
def test_repr(self):
repr(tornadoweb.TornadoRetrying())

def test_old_tornado(self):
old_attr = gen.is_coroutine_function
try:
del gen.is_coroutine_function

# is_coroutine_function was introduced in tornado 4.5;
# verify that we don't *completely* fall over on old versions
@retry
def retryable(thing):
pass
finally:
gen.is_coroutine_function = old_attr


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sitepackages = False
deps =
nose
sphinx
tornado
tornado>=4.5
commands =
py{27,py}: python setup.py nosetests --ignore-files '.*async.py'
py3{5,6}: python setup.py nosetests
Expand Down

0 comments on commit 97cde0d

Please sign in to comment.