-
Notifications
You must be signed in to change notification settings - Fork 40
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
Indirect parametrization of fixture with multiple params with parametrize_with_cases
#150
Comments
Thanks @plammens ! In all honesty I do not like the Maybe I should raise a Feel free to dig in the code to see how to handle this - but I am afraid that this would require some very ugly hack, and there are already a few in pytest-cases :) for example a double-parametrized fixture is actually a single-parametrized fixture where I make myself the cartesian product of parameters, and implement it with a wrapper of the user-provided function... |
Yeah it makes sense it's not worth adding another hack— I agree that
Yeah I think explicitly raising an error is a very good idea. I would say that probably there are very few people relying on it working for single parameter fixtures (although for better or for worse I myself recently used this "feature" 😅), and it isn't explicitly documented how Maybe irrelevant, but it's possible to work around this by using the vanilla |
By the way, I've been looking around and you've got some really awesome libraries/packages! I'm repeatedly finding that you have already written something that makes my life easier in certain recurring programming scenarios. I originally discovered you through the Huge thanks for putting the time into these and distributing them for free, @smarie! |
Thanks @plammens for the kind feedback ! Yes, in general I hate low-level coding so I prefer to spend months solving things once and for all (or until someone else provides a better lib of course), so that I can later focus on more interesting things. If you're curiours, you should probably look into Back to the topic at hand now : your explanation on indirect definitely makes sense. And I'm happy to see that it actually works with cases :) I'll better leave this without explicit ValueError for now, as it makes no big harm. Let's wait for more user feedback on this topic. Note that you can transform any case function into a fixture by having it require a fixture as argument. So you could in your example have your "hand" cases require the dummy player fixture, so that the "hand" case becomes a fully configured player. But then I'm sure we can find another situation in which you wont like this anymore, for example combining subset of cases for the "hand" and for some random other aspect of the player. I need some aspirine now :D |
Proposal to close this: I'll issue a warning when indirect=True and fixture refs are present in the parametrize. |
…ure references are present. See #150
I got here due to the following error: .../pytest_cases/fixture_parametrize_plus.py:831: in _parametrize_plus
raise ValueError("Setting `indirect=True` is not yet supported when at least a `fixure_ref` is present in "
E ValueError: Setting `indirect=True` is not yet supported when at least a `fixure_ref` is present in the `argvalues`. Is this not supported? @pytest_cases.parametrize("subscribe", [fixture_ref("folder")], indirect=True) |
@rena2damas no this is not supported. Usually from my experience you can always find an (elegant) way to use pytest and pytest-cases without using If a fixture is to be parametrized in two different ways for two different tests, I would suggest to create two fixture relying on the same code, or depending on the same root fixture. That way no need for |
I know this might not have been intended to be possible in the first place, but fixtures that take multiple parameters can't be indirectly parametrized with
parametrize_with_cases
:This raises a
ValueError
before the fixture is invoked. (BTW this does work if the fixture has only a single parameter.)python-pytest-cases/pytest_cases/fixture_core2.py
Lines 458 to 463 in ae942d7
(in the above passage,
request.param
is aLazyValue
).Maybe a way to provide support for this would be to select the parameter of the fixture we want to parametrize in the parametrization target, e.g. with double colon notation as in
"my_fixture::param1"
:This would run
test_foo(42, "z")
as the only invocation oftest_foo
.I stumbled upon this while thinking of a workaround for #149 (fixtures with function scope do recompute values at every invocation, so I was thinking to use a fixture and indirectly parametrize that with the cases).
The text was updated successfully, but these errors were encountered: