Skip to content

Commit 57ccbc7

Browse files
wjsiTinche
authored andcommitted
Support flaky on async tests
1 parent 9f59e28 commit 57ccbc7

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.gitignore

+2-1
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

+7
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ def wrap_in_sync(func, _loop):
173173
"""Return a sync wrapper around an async function executing it in the
174174
current event loop."""
175175

176+
# if the function is already wrapped, we rewrap using the original one
177+
# not using __wrapped__ because the original function may already be
178+
# a wrapped one
179+
if hasattr(func, '_raw_test_func'):
180+
func = func._raw_test_func
181+
176182
@functools.wraps(func)
177183
def inner(**kwargs):
178184
coro = func(**kwargs)
@@ -188,6 +194,7 @@ def inner(**kwargs):
188194
task.exception()
189195
raise
190196

197+
inner._raw_test_func = func
191198
return inner
192199

193200

setup.py

+1
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

+17
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)