-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Order of class fixtures #484
Comments
Original comment by Jurko Gospodnetić (BitBucket: jurko, GitHub: jurko): Don't know exactly how pytest handles fixtures defined inside classes (never used those 😄), but my first thought was: 'Have you tried passing See pytest docs for an example on how to use one fixture from another. But trying to rewrite your code example to do this, I really have to wander - why? Something is missing in that example. Why is Could you perhaps post a more complete example? Unless you are absolutely certain your situation really needs fixed fixture call ordering and nothing else will suffice - in which case someone more knowledgeable about pytest internals will have to help you. 😢 Best regards, |
Original comment by BitBucket: javex, GitHub: javex: I am using something similar to autouse fixtures (xUnit setup on steroids). However, I found the This combination is mainly what creates the problem. Here is a more complete example:
It is a bit arbitrary but I hope it gets over the message: I want to test the matrix consisting of the params of As a result I get the product of those two as testing cases and on each now Now I realize that I could just move the fixtures out of the class and have a single autouse fixture that requires those two, assigns them to However, the code is fairly large and it only applies to this particular test class. So moving it out of the class means polluting the global namespace which I'd like to avoid. And merging all fixtures (currently 3) into one means creating the matrix myself. I realize that this is probably some crazy-ass stuff that nobody ever intended to use but from my perspective it would be the cleanest solution if I could do something like |
Original comment by Jurko Gospodnetić (BitBucket: jurko, GitHub: jurko): What I referred to in my original reply was something like this:
I renamed your fixtures so they get instantiated in an 'invalid' order by default, and then got them to be instantiated in the correct order by explicitly marking the second one as using the first one (i.e. by passing the first one to the second one as an argument). Although, I do not like the approach you take here. Too much seems to be done behind the scene. If I needed such a refactoring, I'd most likely do it something like this (disclaimer: naming chosen only to match the original example):
What I would like to see in pytest is a way to more easily define orthogonal fixture parametrizations. For example using separate decorators, the same as can be done for specific test cases using
That would allow you to refactor by assigning names to each of those decorators and reuse them where needed or simply use their names as something revealing your intent. But on the other hand, I don't think that would buy us much in this scenario and I do not have a more applicable scenario ready here so I guess it all just falls under the 'bikeshedding' category. 😄 Hope this helps. Best regards, |
Original comment by BitBucket: javex, GitHub: javex: Wow, I did not know about |
Original comment by Jurko Gospodnetić (BitBucket: jurko, GitHub: jurko): As I see it, there really is not much difference (except for some syntactic sugar) between:
and:
So I do not really see how having the first technique available would 'solve your original problem'. Best regards, |
Original comment by BitBucket: javex, GitHub: javex: Yeah, you say syntactic sugar but if the matrix is 2x3x3x2x2 then it quickly amounts to very ugly code. But you are right, what you show there is possible. I think we can close this issue since it seems to be a corner case that you can solve with the methods you describe. Thank you for your help :-) |
The wheel package format supports including the license file. This is done using the [metadata] section in the setup.cfg file. For additional information on this feature, see: https://wheel.readthedocs.io/en/stable/index.html#including-the-license-in-the-generated-wheel-file Helps project comply with its own license: > The above copyright notice and this permission notice shall be > included in all copies or substantial portions of the Software.
Originally reported by: BitBucket: javex, GitHub: javex
I have two fixtures on on a class, like this:
The problem here is that
_fixture_1
needs_fixture_0
to be run before_fixture_1
as it needsself.data
to be set. I'd really like to split these two up instead of using a single fixture as they are fairly complex. They are also only used on this particular class, so I'd prefer to not have it outside of my class for organizational purposes.However, if I name the fixtures in such a way that lexicographic ordering is the other way around, they will not be called in the right order. I guess that pytest orders fixtures somehow internally (or maybe it is internal ordering of python?).
Anyways, I'd like some deterministic way of fixture ordering to be documented or configurable. One way I could imagine would be to just document that the will always be lexicographically ordered, thus you can be sure that my above naming would always be in the correct order.
Another way would be some kind of mechanism by which I can require another class fixture, since I would order other fixtures this way by declaring one requires the other.
Do you think such a feature would be possible? Or do you think it is a very special application that doesn't deserve it?
The text was updated successfully, but these errors were encountered: