Parameters to fixtures #11775
-
I am fairly new to pytest and am working on a particular code for which I need some advice. We need to use a setup fixture to setup the test environment which on which we then perform tests. We also need to use the parametrize features to generate the arguments required for the test. These parameters have to be passed to the setup fixture to setup the test environment. The example below describes the scenario.
The result
In this case, we generate parameters x & y using pytest.mark.parameterize() however the test function itself doesn't use these parameters and instead calls the fixture myfixture() which in turn uses the autogenerated parameters x and y. We can use the indirect parameter to parametrize and call the fixture that way too. But I was just curious and wanted to know if this is a valid way of using parametrize with fixtures. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
this is a valid way - but its quite confusing - it would be really nice if we had a better way to spell custom pass in parameters for fixtures a key problem here is that we have a concept of direct/indirect to control whether a parameter should pass to a fixture or override it, but in your case you define a set of new "fixtures" that configure your actual fixture currently we want to avoid documenting that capability as we eventually want to come up with a way to spell this nicely |
Beta Was this translation helpful? Give feedback.
-
Thank you. |
Beta Was this translation helpful? Give feedback.
this is a valid way - but its quite confusing - it would be really nice if we had a better way to spell custom pass in parameters for fixtures
a key problem here is that we have a concept of direct/indirect to control whether a parameter should pass to a fixture or override it, but in your case you define a set of new "fixtures" that configure your actual fixture
currently we want to avoid documenting that capability as we eventually want to come up with a way to spell this nicely