It's not clear what you're trying to acheive here, but reusing inputs generated by Hypothsis gives up most of the power of the framework (including minimal examples, replaying failures, settings options, etc.).
Instead, you can define a global variable for your strategy - or write a function that returns a strategy with @st.composite
- and use that in each of your tests, e.g.
MY_STRATEGY = data_frames(columns=[
column(name="float_col1", elements=floats(allow_nan=True, allow_infinity=True))
])
@given(MY_STRATEGY)
def test_foo(df): ...
@given(MY_STRATEGY)
def test_bar(df): ...
Specifically to answer the question you asked, you cannot get a return value from a function decorated with @given
.
Instead of using fixtures to instantiate your class, try using the .map
method of a strategy (in this case data_frames(...).map(its_an_class)
), or the builds()
strategy (i.e. builds(my_class, data_frames(...), ...)
).