diff --git a/pytest_trio/_tests/test_hypothesis_interaction.py b/pytest_trio/_tests/test_hypothesis_interaction.py index c4f0053..30a37db 100644 --- a/pytest_trio/_tests/test_hypothesis_interaction.py +++ b/pytest_trio/_tests/test_hypothesis_interaction.py @@ -1,5 +1,9 @@ import pytest import trio +from trio.tests.test_scheduler_determinism import ( + scheduler_trace, test_the_trio_scheduler_is_not_deterministic, + test_the_trio_scheduler_is_deterministic_if_seeded +) from hypothesis import given, settings, strategies as st from pytest_trio.plugin import _trio_test_runner_factory @@ -33,30 +37,6 @@ async def test_mark_and_parametrize(x, y): assert y in (1, 2) -async def scheduler_trace(): - """Returns a scheduler-dependent value we can use to check determinism.""" - trace = [] - - async def tracer(name): - for i in range(10): - trace.append((name, i)) - await trio.sleep(0) - - async with trio.open_nursery() as nursery: - for i in range(5): - nursery.start_soon(tracer, i) - - return tuple(trace) - - -def test_the_trio_scheduler_is_not_deterministic(): - # At least, not yet. See https://github.com/python-trio/trio/issues/32 - traces = [] - for _ in range(10): - traces.append(trio.run(scheduler_trace)) - assert len(set(traces)) == len(traces) - - def test_the_trio_scheduler_is_deterministic_under_hypothesis(): traces = [] diff --git a/pytest_trio/plugin.py b/pytest_trio/plugin.py index 0b9b2b4..c64839b 100644 --- a/pytest_trio/plugin.py +++ b/pytest_trio/plugin.py @@ -31,6 +31,10 @@ # even though it uses a module-scoped Random instance. This works # regardless of whether or not the random_module strategy is used. register_random(trio._core._run._r) + # We also have to enable determinism, which is disabled by default + # due to a small performance impact - but fine to enable in testing. + # See https://github.com/python-trio/trio/pull/890/ for details. + trio._core._run._ALLOW_DETERMINISTIC_SCHEDULING = True def pytest_addoption(parser):