I am writing a simple test code in Python using the Hypothesis package. It there a way to use multiple strategies for the same function parameter? As an example, use integers()
and floats()
to test my values
parameter without writing two separate test functions?
from hypothesis import given
from hypothesis.strategies import lists, integers, floats, sampled_from
@given(
integers() ,floats()
)
def test_lt_operator_interval_bin_numerical(values):
interval_bin = IntervalBin(10, 20, IntervalClosing.Both)
assert (interval_bin < values) == (interval_bin.right < values)
The above code doesn't work, but it represents what i would like to achieve.
NB: I have already tried the trivial solution of creating two different tests with two different strategies:
def _test_lt(values):
interval_bin = IntervalBin(10, 20, IntervalClosing.Both)
assert (interval_bin < values) == (interval_bin.right < values)
test_lt_operator_interval_bin_int = given(integers())(_test_lt)
test_lt_operator_interval_bin_float = given(floats())(_test_lt)
However I was wondering if there was a nicer way to do this: when the nummber of strategies becomes larger, it is quite redundant as code.