Skip to content

Commit

Permalink
Deterministic scheduling via Hypothesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jan 22, 2019
1 parent e828788 commit 3775f98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions newsfragments/73.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest-trio now makes the Trio scheduler deterministic while running
inside a Hypothesis test. Hopefully you won't see any change, but if
you had scheduler-dependent bugs Hypothesis will be more effective now.
13 changes: 12 additions & 1 deletion pytest_trio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
# Ordered dict (and **kwargs) not available with Python<3.6
ORDERED_DICTS = False

try:
from hypothesis import register_random
except ImportError: # pragma: no cover
pass
else:
# On recent versions of Hypothesis, make the Trio scheduler deterministic
# 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)


def pytest_addoption(parser):
parser.addini(
Expand Down Expand Up @@ -345,7 +355,8 @@ def pytest_runtest_call(item):
item.obj.hypothesis.inner_test = _trio_test_runner_factory(
item, item.obj.hypothesis.inner_test
)
elif getattr(item.obj, 'is_hypothesis_test', False):
elif getattr(item.obj, 'is_hypothesis_test',
False): # pragma: no cover
pytest.fail(
'test function `%r` is using Hypothesis, but pytest-trio '
'only works with Hypothesis 3.64.0 or later.' % item
Expand Down

0 comments on commit 3775f98

Please sign in to comment.