This is useful because it works even for users without pytest-trio installed or enabled (c.f. https://github.com/HypothesisWorks/hypothesis/issues/3940), e.g. because they're using unittest or running a test function by hand in some debugging loop or the test function calls trio.run() internally, and it will allow pytest-trio to avoid importing Hypothesis if it wasn't otherwise going to be used (which is nice for performance).
pytest-trio
does two things for property-based tests with Hypothesis:pytest-trio
is clearly the right place to do that.Random
instance so that the scheduler is deterministic and Hypothesis can replay failing examples (see https://github.com/python-trio/pytest-trio/pull/73 and https://github.com/python-trio/trio/pull/890/).At the time,
pytest-trio
was the right place to do (2), but not anymore: since https://github.com/HypothesisWorks/hypothesis/pull/2556, it's possible for Trio to ship a Hypothesis plugin which handles the registration if-and-only-if Hypothesis is imported. Here are the docs.This is useful because it works even for users without
pytest-trio
installed or enabled (c.f. https://github.com/HypothesisWorks/hypothesis/issues/3940), e.g. because they're usingunittest
or running a test function by hand in some debugging loop or the test function callstrio.run()
internally, and it will allowpytest-trio
to avoid importing Hypothesis if it wasn't otherwise going to be used (which is nice for performance).