Skip to content

Commit 229d3ba

Browse files
committed
Work on
1 parent e4583f6 commit 229d3ba

File tree

3 files changed

+13
-50
lines changed

3 files changed

+13
-50
lines changed

pytest_asyncio/_runner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ def run_test(self, coro: Awaitable[None]) -> None:
2929
raise
3030

3131
def set_timer(self, timeout: Union[int, float]) -> None:
32-
assert self._timeout_hande is None
32+
if self._timeout_hande is not None:
33+
self._timeout_hande.cancel()
3334
self._timeout_reached = False
3435
self._timeout_hande = self._loop.call_later(timeout, self._on_timeout)
3536

3637
def cancel_timer(self) -> None:
37-
assert self._timeout_hande is not None
38-
self._timeout_hande.cancel()
38+
if self._timeout_hande is not None:
39+
self._timeout_hande.cancel()
3940
self._timeout_reached = False
4041
self._timeout_hande = None
4142

pytest_asyncio/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def pytest_fixture_setup(
294294
if fixturedef.argname == "event_loop":
295295
outcome = yield
296296
loop = outcome.get_result()
297+
print("\ninstall runner", request.node, id(request.node), id(loop))
297298
_install_runner(request.node, loop)
298299
policy = asyncio.get_event_loop_policy()
299300
try:

tests/test_timeout.py

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ def test_timeout_ok(pytester):
1010
import asyncio
1111
import pytest
1212
13-
pytest_plugins = 'pytest_asyncio'
13+
pytest_plugins = ['pytest_asyncio']
1414
15-
@pytest.mark.asyncio(timeout=0.01)
1615
@pytest.mark.xfail(strict=True, raises=asyncio.TimeoutError)
16+
@pytest.mark.timeout(0.01)
17+
@pytest.mark.asyncio
1718
async def test_a():
1819
await asyncio.sleep(1)
1920
"""
@@ -30,9 +31,10 @@ def test_timeout_disabled(pytester):
3031
import asyncio
3132
import pytest
3233
33-
pytest_plugins = 'pytest_asyncio'
34+
pytest_plugins = ['pytest_asyncio']
3435
35-
@pytest.mark.asyncio(timeout=0)
36+
@pytest.mark.timeout(0)
37+
@pytest.mark.asyncio
3638
async def test_a():
3739
await asyncio.sleep(0.01)
3840
"""
@@ -42,34 +44,14 @@ async def test_a():
4244
result.assert_outcomes(passed=1)
4345

4446

45-
def test_timeout_not_numeric(pytester):
46-
pytester.makepyfile(
47-
dedent(
48-
"""\
49-
import asyncio
50-
import pytest
51-
52-
pytest_plugins = 'pytest_asyncio'
53-
54-
@pytest.mark.asyncio(timeout="abc")
55-
@pytest.mark.xfail(strict=True, raises=ValueError)
56-
async def test_a():
57-
await asyncio.sleep(0.01)
58-
"""
59-
)
60-
)
61-
result = pytester.runpytest("--asyncio-mode=strict")
62-
result.assert_outcomes(xfailed=1)
63-
64-
6547
def test_timeout_cmdline(pytester):
6648
pytester.makepyfile(
6749
dedent(
6850
"""\
6951
import asyncio
7052
import pytest
7153
72-
pytest_plugins = 'pytest_asyncio'
54+
pytest_plugins = ['pytest_asyncio']
7355
7456
@pytest.mark.asyncio
7557
@pytest.mark.xfail(strict=True, raises=asyncio.TimeoutError)
@@ -78,26 +60,5 @@ async def test_a():
7860
"""
7961
)
8062
)
81-
result = pytester.runpytest("--asyncio-timeout=0.01", "--asyncio-mode=strict")
82-
result.assert_outcomes(xfailed=1)
83-
84-
85-
def test_timeout_cfg(pytester):
86-
pytester.makepyfile(
87-
dedent(
88-
"""\
89-
import asyncio
90-
import pytest
91-
92-
pytest_plugins = 'pytest_asyncio'
93-
94-
@pytest.mark.asyncio
95-
@pytest.mark.xfail(strict=True, raises=asyncio.TimeoutError)
96-
async def test_a():
97-
await asyncio.sleep(1)
98-
"""
99-
)
100-
)
101-
pytester.makefile(".ini", pytest="[pytest]\nasyncio_timeout = 0.01\n")
102-
result = pytester.runpytest("--asyncio-mode=strict")
63+
result = pytester.runpytest("--timeout=0.01", "--asyncio-mode=strict")
10364
result.assert_outcomes(xfailed=1)

0 commit comments

Comments
 (0)