It depends on whether you want to restrict for one test or for all, but approach is similar and based on settings.
Configuring single test
To change default behavior for some of tests we can decorate them with settings
object like
from hypothesis import given, settings, strategies
@given(strategies.integers())
@settings(max_examples=10)
def test_this_a_little(x):
...
@given(strategies.integers())
@settings(max_examples=1000)
def test_this_many_times(x):
...
for test_this_a_little
there will be 10
examples generated (at most) and for test_this_many_times
there will be 1000
.
Configuring all tests
To change default behavior for all tests somewhere during bootstrap of your test run (e.g. for pytest
it can be conftest.py
module) we can define a custom hypothesis
settings profile and then use it during tests invocation like
from hypothesis import settings
settings.register_profile('my-profile-name',
max_examples=10)
and after that (assuming that you are using pytest
)
> pytest --hypothesis-profile=my-profile-name
Further reading
hypothesis
is pretty awesome and allows us to configure many things, available options are listed in the docs.