Skip to content

Commit

Permalink
Add tests for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentVanlaer committed Sep 3, 2023
1 parent 7404b79 commit 797a19a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pytest_trio/_tests/test_timeout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import trio
import functools


def test_timeout(testdir):
testdir.makepyfile(
"""
from trio import sleep
import pytest
import pytest_trio.timeout
@pytest.mark.timeout(0.01)
@pytest.mark.trio
async def test_will_timeout():
await sleep(10)
"""
)

testdir.makefile(".ini", pytest="[pytest]\ntrio_timeout=true\n")

result = testdir.runpytest()

result.stdout.fnmatch_lines(["Timeout reached"])
result.assert_outcomes(failed=1)


def test_timeout_strict_exception_group(testdir, monkeypatch):
monkeypatch.setattr(trio, "run", functools.partial(trio.run, strict_exception_groups=True))

testdir.makepyfile(
"""
from trio import sleep
import pytest
import pytest_trio.timeout
@pytest.mark.timeout(0.01)
@pytest.mark.trio
async def test_will_timeout():
await sleep(10)
"""
)

testdir.makefile(".ini", pytest="[pytest]\ntrio_timeout=true\n")

result = testdir.runpytest()

result.stdout.fnmatch_lines(["Timeout reached"])
result.assert_outcomes(failed=1)

0 comments on commit 797a19a

Please sign in to comment.