-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fixture order considering global states #4892
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
Comments
This very interesting request seems quite interdependent with the new order optimization algorithm (#3551), your own param-priority (#3393) plugin, etc. I am personally interested because in pytest-cases when fixture unions are used, a new parameter 'NOT_USED" is added to fixtures that are not used in some callspecs, so that they are not setup/torn down. So I would like to be sure that there is no particular gotcha around higher-level scope ordering concerning them. |
Having a second look at this topic, I think that part of it can be solved by your plugin. Indeed the main problem comes from the fact that I tried this:
but... it does not work :( Of course this would not solve the "shared resource" issue but at least it would solve the "modarg and otherarg take much more time to setup/teardown" issue |
This won't have any effect in the That's why this will not have any effect:
Because there is are parameter marks in this fixture function. |
ah i see, thanks for clarifying this! |
Hi,
This section of the documentation automatic grouping of tests by fixtures instances almost solves one need we are having, related to fixtures dealing with global states.
Problem example
To exemplify, let's simplify the example on the documentation, with seemly independent tests, each one with its fixture (
modarg
withtest_1
; andotherarg
withtest_2
).modarg
andotherarg
change the same global state.It is not a problem because pytest orders in such a way that all tests using one fixture are executed, then all tests using the another:
Now, let's say I want to refactor the
['a', 'b']
parameters into a common fixture.The problem now is that pytest tries to first use the new, highest level
uppermost
fixture first, now interleaving the execution of the fixturesmodarg
andotherarg
(which is a problem because they aremodule
scoped and are dealing with the same shared resource).Needed behaviour
In our situation, the resource is a piece of hardware, and the
module
-scoped fixture is an expensive set-up of that hardware (start-up and configuration).For this case, it would solve to be able to specify that a given fixture share a resource - so, when ordering, pytest can make sure that there is no interleaving between the execution of tests that share that same resource.
So in our example, we would possibly have this:
And that's it. I would like to hear if this is sensible to add or not, probably more experienced developers might spot any detrimental side effects of this. I would be willing to implement this myself once we decide it could and should be done.
Thanks!
The text was updated successfully, but these errors were encountered: