diff --git a/.gitignore b/.gitignore index 09758085..447dbc4d 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,5 @@ docs/_build/ target/ .venv* -.idea \ No newline at end of file +.idea +.vscode \ No newline at end of file diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 7665ff4d..c96d40ba 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -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) @@ -201,6 +207,7 @@ def inner(**kwargs): task.exception() raise + inner._raw_test_func = func return inner diff --git a/setup.py b/setup.py index e15080fe..198bad69 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,7 @@ def find_version(): "testing": [ "coverage", "hypothesis >= 5.7.1", + "flaky >= 3.5.0" ], }, entry_points={"pytest11": ["asyncio = pytest_asyncio.plugin"]}, diff --git a/tests/test_flaky_integration.py b/tests/test_flaky_integration.py new file mode 100644 index 00000000..4628c6a0 --- /dev/null +++ b/tests/test_flaky_integration.py @@ -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