I need to run a mixture of unit tests and property-based tests in Python. My current test code runs them separately, and thus duplicates some code:
@pytest.mark.parametrize("values", list_of_values)
def test_my_function(a_value):
call_test(a_value)
@given(st.arbitrary_values())
def test_hypothesis_my_function(a_value):
call_test(a_value)
There's a code repetition above: test_my_function
and test_hypothesis_my_function
are the same, just triggered by unit and property-based infrastructure respectively.
I would prefer to eliminate the code repetition above to obtain something like this:
@pytest.mark.parametrize("values", list_of_values)
@given(st.arbitrary_values())
def test_my_function(a_value):
call_test(a_value)
Can this effect be attained? Thanks in advance.