Skip to content

Commit 8ff6718

Browse files
Add tests for timeouts
1 parent fb245f6 commit 8ff6718

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

pytest_trio/_tests/test_timeout.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import trio
2+
import functools
3+
4+
5+
def test_timeout(testdir):
6+
testdir.makepyfile(
7+
"""
8+
from trio import sleep
9+
import pytest
10+
import pytest_trio.timeout
11+
12+
@pytest.mark.timeout(0.01)
13+
@pytest.mark.trio
14+
async def test_will_timeout():
15+
await sleep(10)
16+
"""
17+
)
18+
19+
testdir.makefile(".ini", pytest="[pytest]\ntrio_timeout=true\n")
20+
21+
result = testdir.runpytest()
22+
23+
result.stdout.fnmatch_lines(["Timeout reached"])
24+
result.assert_outcomes(failed=1)
25+
26+
27+
def test_timeout_strict_exception_group(testdir, monkeypatch):
28+
monkeypatch.setattr(
29+
trio, "run", functools.partial(trio.run, strict_exception_groups=True)
30+
)
31+
32+
testdir.makepyfile(
33+
"""
34+
from trio import sleep
35+
import pytest
36+
import pytest_trio.timeout
37+
38+
@pytest.mark.timeout(0.01)
39+
@pytest.mark.trio
40+
async def test_will_timeout():
41+
await sleep(10)
42+
"""
43+
)
44+
45+
testdir.makefile(".ini", pytest="[pytest]\ntrio_timeout=true\n")
46+
47+
result = testdir.runpytest()
48+
49+
result.stdout.fnmatch_lines(["Timeout reached"])
50+
result.assert_outcomes(failed=1)

0 commit comments

Comments
 (0)