Skip to content

Commit 58c7bb5

Browse files
committed
Support flaky on async tests
1 parent f21e0da commit 58c7bb5

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ docs/_build/
5858
target/
5959

6060
.venv*
61-
.idea
61+
.idea
62+
.vscode

pytest_asyncio/plugin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ def wrap_in_sync(func, _loop):
186186
"""Return a sync wrapper around an async function executing it in the
187187
current event loop."""
188188

189+
# if the function is already wrapped, we rewrap using the original one
190+
# not using __wrapped__ because the original function may already be
191+
# a wrapped one
192+
if hasattr(func, '_raw_test_func'):
193+
func = func._raw_test_func
194+
189195
@functools.wraps(func)
190196
def inner(**kwargs):
191197
coro = func(**kwargs)
@@ -201,6 +207,7 @@ def inner(**kwargs):
201207
task.exception()
202208
raise
203209

210+
inner._raw_test_func = func
204211
return inner
205212

206213

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def find_version():
4747
"testing": [
4848
"coverage",
4949
"hypothesis >= 5.7.1",
50+
"flaky >= 3.5.0"
5051
],
5152
},
5253
entry_points={"pytest11": ["asyncio = pytest_asyncio.plugin"]},

tests/test_flaky_integration.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Tests for the Flaky integration, which retries failed tests.
2+
"""
3+
import asyncio
4+
5+
import flaky
6+
import pytest
7+
8+
_threshold = -1
9+
10+
11+
@flaky.flaky(3, 2)
12+
@pytest.mark.asyncio
13+
async def test_asyncio_flaky_thing_that_fails_then_succeeds():
14+
global _threshold
15+
await asyncio.sleep(0.1)
16+
_threshold += 1
17+
assert _threshold != 1

0 commit comments

Comments
 (0)