2

此示例是文档中示例的变体:

import hypothesis.strategies as st

from hypothesis import given

@st.composite
def s(draw):
    x = draw(st.text(), min_size=1)
    y = draw(st.text(alphabet=x))
    return (x, y)



@given(s1=s, s2=s)
def test_subtraction(s1, s2):

    print(s1, s2)

    assert 0

它失败:

E hypothesis.errors.InvalidArgument: Expected SearchStrategy but got <function accept.<locals>.s at 0x7fd7e5c05620> (type=function)

/mnt/work/unfuncat/software/anaconda/lib/python3.6/site-packages/hypothesis/internal/validation.py:40: InvalidArgument

我究竟做错了什么?

4

1 回答 1

2

您需要调用复合函数。这在文档中没有解释,但在2016 年的博客文章中有一个示例。

@given(s1=s(), s2=s()) # <===== change
def test_subtraction(s1, s2):

    print(s1, s2)

    assert 0
于 2018-06-15T13:36:15.763 回答