You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enable fixture dynamic scoping during test run #6101
Tried to use dynamic scopes for fixtures. However, the scope definition is executed only once - during the fixture definition.
We would like to have option to control fixture scope during test run.
This will allow code re-use in tests which need the code in different scope.
For example: set up a docker - one test needs it in function level and a separate test needs it in module level.
@rnetser we do have plans to enable fixtures to be available at multiple scopes (i don't have the issue number ready),
we don't yet have a plan to allow the test to do the detailed picking as its not yet clear how the concepts integrate
@aklajnert what you outlined is the current workaround, thanks for taking the time to put it together
@rnetser unfortunately there isn't, when we tried to add the feature for pytest 3.0 in the pytest sprint in Freiburg, we learned that the current conceptual layout of the fixture system makes this feature error prone (@nicoddemus didnt spare efforts to make it work then, however one unexpected bug after another turned up, as such we had to stop and rethink)
so far we haven't found the time to find a conceptual layout that makes this feature solid
Activity
aklajnert commentedon Nov 12, 2019
How about extracting fixture body into a separate function, and define two fixtures with different scopes that will call the function?
RonnyPfannschmidt commentedon Nov 12, 2019
@rnetser we do have plans to enable fixtures to be available at multiple scopes (i don't have the issue number ready),
we don't yet have a plan to allow the test to do the detailed picking as its not yet clear how the concepts integrate
@aklajnert what you outlined is the current workaround, thanks for taking the time to put it together
rnetser commentedon Nov 12, 2019
@aklajnert thanks, this is what we have implemented as a workaround.
@RonnyPfannschmidt is there a timeline for this?
RonnyPfannschmidt commentedon Nov 12, 2019
@rnetser unfortunately there isn't, when we tried to add the feature for pytest 3.0 in the pytest sprint in Freiburg, we learned that the current conceptual layout of the fixture system makes this feature error prone (@nicoddemus didnt spare efforts to make it work then, however one unexpected bug after another turned up, as such we had to stop and rethink)
so far we haven't found the time to find a conceptual layout that makes this feature solid
victormaricato commentedon Apr 1, 2021
@rnetser @nicoddemus now with
pytest 6.2.2, do you think this feature is somehow more tangible? Can you share your thoughts on the implementation?RonnyPfannschmidt commentedon Apr 1, 2021
@maricatovictor we didnt touch the relevant fixture internals as of now