|
22 | 22 | # Ordered dict (and **kwargs) not available with Python<3.6 |
23 | 23 | ORDERED_DICTS = False |
24 | 24 |
|
| 25 | +try: |
| 26 | + from hypothesis import register_random |
| 27 | +except ImportError: # pragma: no cover |
| 28 | + pass |
| 29 | +else: |
| 30 | + # On recent versions of Hypothesis, make the Trio scheduler deterministic |
| 31 | + # even though it uses a module-scoped Random instance. This works |
| 32 | + # regardless of whether or not the random_module strategy is used. |
| 33 | + 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 |
| 38 | + |
25 | 39 |
|
26 | 40 | def pytest_addoption(parser): |
27 | 41 | parser.addini( |
@@ -225,7 +239,7 @@ async def run(self, test_ctx, contextvars_ctx): |
225 | 239 | # should cancel them. |
226 | 240 | assert not self.user_done_events |
227 | 241 | func_value = None |
228 | | - with trio.open_cancel_scope() as cancel_scope: |
| 242 | + with trio.CancelScope() as cancel_scope: |
229 | 243 | test_ctx.test_cancel_scope = cancel_scope |
230 | 244 | assert not test_ctx.crashed |
231 | 245 | await self._func(**resolved_kwargs) |
@@ -270,7 +284,7 @@ async def run(self, test_ctx, contextvars_ctx): |
270 | 284 | except BaseException as exc: |
271 | 285 | assert isinstance(exc, trio.Cancelled) |
272 | 286 | test_ctx.crash(None) |
273 | | - with trio.open_cancel_scope(shield=True): |
| 287 | + with trio.CancelScope(shield=True): |
274 | 288 | for event in self.user_done_events: |
275 | 289 | await event.wait() |
276 | 290 |
|
@@ -345,7 +359,8 @@ def pytest_runtest_call(item): |
345 | 359 | item.obj.hypothesis.inner_test = _trio_test_runner_factory( |
346 | 360 | item, item.obj.hypothesis.inner_test |
347 | 361 | ) |
348 | | - elif getattr(item.obj, 'is_hypothesis_test', False): |
| 362 | + elif getattr(item.obj, 'is_hypothesis_test', |
| 363 | + False): # pragma: no cover |
349 | 364 | pytest.fail( |
350 | 365 | 'test function `%r` is using Hypothesis, but pytest-trio ' |
351 | 366 | 'only works with Hypothesis 3.64.0 or later.' % item |
|
0 commit comments