Skip to content

Adapt test cases to pytest-asyncio 1.0 compatibility #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 2 additions & 51 deletions tests/test_backoff_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ async def exceptor():


@pytest.mark.asyncio
async def test_on_exception_coro_cancelling(event_loop):
async def test_on_exception_coro_cancelling():
sleep_started_event = asyncio.Event()

@backoff.on_predicate(backoff.expo)
Expand All @@ -679,59 +679,10 @@ async def coro():

return False

task = event_loop.create_task(coro())
task = asyncio.create_task(coro())

await sleep_started_event.wait()

task.cancel()

assert (await task)


def test_on_predicate_on_regular_function_without_event_loop(monkeypatch):
monkeypatch.setattr('time.sleep', lambda x: None)

# Set default event loop to None.
loop = asyncio.get_event_loop()
asyncio.set_event_loop(None)

try:
@backoff.on_predicate(backoff.expo)
def return_true(log, n):
val = (len(log) == n - 1)
log.append(val)
return val

log = []
ret = return_true(log, 3)
assert ret is True
assert 3 == len(log)

finally:
# Restore event loop.
asyncio.set_event_loop(loop)


def test_on_exception_on_regular_function_without_event_loop(monkeypatch):
monkeypatch.setattr('time.sleep', lambda x: None)

# Set default event loop to None.
loop = asyncio.get_event_loop()
asyncio.set_event_loop(None)

try:
@backoff.on_exception(backoff.expo, KeyError)
def keyerror_then_true(log, n):
if len(log) == n:
return True
e = KeyError()
log.append(e)
raise e

log = []
assert keyerror_then_true(log, 3) is True
assert 3 == len(log)

finally:
# Restore event loop.
asyncio.set_event_loop(loop)