Skip to content

Resolve event loop closed issue when trying a second attempt with flaky #220

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

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ docs/_build/
target/

.venv*
.idea
.idea
.vscode
7 changes: 7 additions & 0 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def wrap_in_sync(func, _loop):
"""Return a sync wrapper around an async function executing it in the
current event loop."""

# if the function is already wrapped, we rewrap using the original one
# not using __wrapped__ because the original function may already be
# a wrapped one
if hasattr(func, '_raw_test_func'):
func = func._raw_test_func

@functools.wraps(func)
def inner(**kwargs):
coro = func(**kwargs)
Expand All @@ -201,6 +207,7 @@ def inner(**kwargs):
task.exception()
raise

inner._raw_test_func = func
return inner


Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def find_version():
"testing": [
"coverage",
"hypothesis >= 5.7.1",
"flaky >= 3.5.0"
],
},
entry_points={"pytest11": ["asyncio = pytest_asyncio.plugin"]},
Expand Down
17 changes: 17 additions & 0 deletions tests/test_flaky_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for the Flaky integration, which retries failed tests.
"""
import asyncio

import flaky
import pytest

_threshold = -1


@flaky.flaky(3, 2)
@pytest.mark.asyncio
async def test_asyncio_flaky_thing_that_fails_then_succeeds():
global _threshold
await asyncio.sleep(0.1)
_threshold += 1
assert _threshold != 1