File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import pytest
22import trio
3+ from trio .tests .test_scheduler_determinism import (
4+ scheduler_trace , test_the_trio_scheduler_is_not_deterministic ,
5+ test_the_trio_scheduler_is_deterministic_if_seeded
6+ )
37from hypothesis import given , settings , strategies as st
48
59from pytest_trio .plugin import _trio_test_runner_factory
@@ -33,30 +37,6 @@ async def test_mark_and_parametrize(x, y):
3337 assert y in (1 , 2 )
3438
3539
36- async def scheduler_trace ():
37- """Returns a scheduler-dependent value we can use to check determinism."""
38- trace = []
39-
40- async def tracer (name ):
41- for i in range (10 ):
42- trace .append ((name , i ))
43- await trio .sleep (0 )
44-
45- async with trio .open_nursery () as nursery :
46- for i in range (5 ):
47- nursery .start_soon (tracer , i )
48-
49- return tuple (trace )
50-
51-
52- def test_the_trio_scheduler_is_not_deterministic ():
53- # At least, not yet. See https://github.com/python-trio/trio/issues/32
54- traces = []
55- for _ in range (10 ):
56- traces .append (trio .run (scheduler_trace ))
57- assert len (set (traces )) == len (traces )
58-
59-
6040def test_the_trio_scheduler_is_deterministic_under_hypothesis ():
6141 traces = []
6242
Original file line number Diff line number Diff line change 3131 # even though it uses a module-scoped Random instance. This works
3232 # regardless of whether or not the random_module strategy is used.
3333 register_random (trio ._core ._run ._r )
34+ # We also have to enable determinism, which is disabled by default
35+ # due to a small performance impact - but fine to enable in testing.
36+ # See https://github.com/python-trio/trio/pull/890/ for details.
37+ trio ._core ._run ._ALLOW_DETERMINISTIC_SCHEDULING = True
3438
3539
3640def pytest_addoption (parser ):
You can’t perform that action at this time.
0 commit comments