-
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
Callable case generator with fixtures? #308
Comments
What you want to is not possible with pytest in general. Regarding |
@jgersti ah, bummer. that explains some things. Thanks for looking into this, I appreciate your help! |
I would like to be able to parameterize a test/function whose cases are generated by a class.
The class would be able to use fixtures during the case-generation process (i.e. collection stage).
In the docs there is this example of a case generator (abbreviated):
This works, but I'd like:
who
values('you', 'there')
to come from a callable (rather than hard-coded in the decorator).Below, I've added two superficial fixtures and a
my_callable
function to generate values for thewho
parameter.This fails with:
Ok, so it looks like
@parametrize
doesn't want to be given a callable; It wants to be given a resolved list of values. No problem, I can just callmy_callable
, and pass the results to the@parametrize
decorator, e.g.That results in this error:
...which I guess makes sense, but now I'm not sure how to proceed. I'm sure you've documented this (or a better/simpler approach) somewhere, so my apologies ahead of time. Any guidance/links would be much appreciated!
Thank you!
Bonus puzzle
Continuing from that last attempt/failure, rather than augmenting the signature of
my_callable
(to indicate the need offixture1
andfixture2
), I figured maybe I could use@pytest.mark.usefixtures
instead. And you know what, this actually "worked" !!...except that it never actually ran/called the fixtures☹️
I would have thought there would be an error or warning if those fixtures were not run (since clearly I don't know what I'm doing), rather than silently failing (and in this case, passing)
Thanks so much for the work you've done!
The text was updated successfully, but these errors were encountered: