I created custom Hypothesis strategies using builds()
and @composite
(the design is inspired by this example from the docs). The strategies are designed similar to the pseudo code below:
# strategies.py
from hypothesis.strategies import builds, composite, draw, floats, integers
class SutConfiguration:
""" Data which represents the configuration of the system under test. """
def __init__(self, integer, float):
self.integer = integer
self.float = float
# custom strategy which uses builds()
SutConfigurationStrategy = builds(
SutConfiguration,
integer=integers(min_value=APP_SPECIFIC_INT_MIN, max_value=APP_SPECIFIC_INT_MAX),
float=floats(min_value=APP_SPECIFIC_FLOAT_MIN, max_value=APP_SPECIFIC_FLOAT_MAX),
)
@composite
def overall_test_configuration(draw, sut_st=SutConfigurationStrategy, env_st=SutEnvironmentStrategy):
"""Custom strategy which uses draw."""
sut_config = draw(sut_st)
env_config = draw(env_st)
return (sut_config, rc_stereomatching_config, env_config)
The strategy is uses as usual e.g. using unittest
as test runner:
# test.py
import unittest
from <package>.strategies import overall_test_configuration
class TestSut(unittest.TestCase):
"""Class containing several tests for the system under test."""
@given(overall_test_configuration())
def test_something():
"""Test which uses overall_test_configuration"""
...
Now I would like to make the strategies configurable to the actual application to define e.g. min_value
in integers(min_value=APP_SPECIFIC_INT_MIN, ...)
when defining the test function. This can be done for @composite
strategies via agruments like done here. But how can I make the strategies which use builds()
configurable?