hypothesis
有很多策略,我仍在努力理解它们。看看它们产生了哪些价值对我有很大帮助。那可能吗?
MVCE
hypothesis==5.18.3
和pydantic==1.5.1
:_
from typing import Optional
from hypothesis import given
from hypothesis.strategies import from_type
from pydantic import BaseModel
class Adress(BaseModel):
city: str
street: str
house_number: int
postal_code: int
class Person(BaseModel):
prename: str
middlename: Optional[str]
lastname: str
address: Adress
@given(from_type(Person))
def test_me(person: Person):
seen = [
Person(
prename="",
middlename=None,
lastname="",
address=Adress(city="", street="", house_number=0, postal_code=0),
),
Person(
prename="0",
middlename=None,
lastname="",
address=Adress(city="", street="", house_number=0, postal_code=0),
),
Person(
prename="",
middlename=None,
lastname="0",
address=Adress(city="", street="", house_number=0, postal_code=0),
),
Person(
prename="",
middlename=None,
lastname="",
address=Adress(city="", street="0", house_number=0, postal_code=0),
),
]
assert person in seen
如您所见,我目前弄清楚假设在做什么的方法是手动将其添加到此seen
列表中。有没有办法将策略用作生成器/生成策略测试的值列表?