0

In my unit tests I use the same combination of strategies fairly often:

import hypothesis.strategies as st

@given(st.text(), st.integers(), st.floats())
def test_stuff(text, integer, float):
    ...

I was hoping I could extract that combination like so:

def combo():
    return st.tuples(st.text(), st.integers(), st.floats())

So that I could use it in this shorter way:

@given(combo())
def test_stuff(text, integer, float):
    ...

However, then I get fixture 'text' not found. Is there a way to achieve what I want with Hypothesis?

Max Power
  • 952
  • 9
  • 24

1 Answers1

0

Your specific idea is not supported, because there must always be a one-to-one correspondence between arguments to @given() and to the test function.

However, there are a couple of workarounds you could use:

  • as juanpa.arrivillaga suggested, you could unpack your arguments within the test function
  • alternatively, you could have a global dictionary of common = {"text": ..., "integer": ..., etc} and then unpack it with @given(**common)
Zac Hatfield-Dodds
  • 2,455
  • 6
  • 19