-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add generators to case functions. #319
Comments
Thanks @jenstroeger ! I am curious to see the thoughts of the community of users here |
I think the feature itself would be useful and offer a lot of flexibility to improve automated, larger test sets — for example I’d create a generator which randomly picks a large number of example cases from a Faker provider.1 How nice would that be 🤓 As for implementing that in your package and answering the above questions, I’m not fluent enough with the details of the Footnotes
|
@smarie any more thoughts on this? As for an example, I think using pytest-repeat combined with a case function that produces random data using Faker would be neat. Something like this: # The case function returns a generator.
def case_names() -> Generator[str]:
fake = Faker()
while True:
yield fake.name()
# We need to specify where to draw test cases from. The decorator order probably matters.
# Now the `cases` argument is a generator object from which values can be pulled.
@parametrize("name", cases=case_names())
@pytest.mark.repeat(10)
def test_something_faker(name: str) -> None:
assert something_to_test(name) So, basically, if the case function is a generator then just next() a value from it (I think even allow StopIteration to raise and fail testing) and pass that value to the test function. This way, I can use the |
Following issue #229 and the discussion there, adding generators to case function requires discussion and some work:
Let the conversation begin 🤓
The text was updated successfully, but these errors were encountered: