Skip to content

Commit 797a19a

Browse files
Add tests for timeouts
1 parent 7404b79 commit 797a19a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Diff for: pytest_trio/_tests/test_timeout.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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(trio, "run", functools.partial(trio.run, strict_exception_groups=True))
29+
30+
testdir.makepyfile(
31+
"""
32+
from trio import sleep
33+
import pytest
34+
import pytest_trio.timeout
35+
36+
@pytest.mark.timeout(0.01)
37+
@pytest.mark.trio
38+
async def test_will_timeout():
39+
await sleep(10)
40+
"""
41+
)
42+
43+
testdir.makefile(".ini", pytest="[pytest]\ntrio_timeout=true\n")
44+
45+
result = testdir.runpytest()
46+
47+
result.stdout.fnmatch_lines(["Timeout reached"])
48+
result.assert_outcomes(failed=1)

0 commit comments

Comments
 (0)