-
Notifications
You must be signed in to change notification settings - Fork 35
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
Support for reordering tests based on dependencies #44
base: develop
Are you sure you want to change the base?
Conversation
Wanted to add that this new functionality could be gated behind a command line option too, if needed. |
@DevilXD, for some reason this fix reverses the order of all the test cases, so I have to use reverse package to make it correct again. |
I'm... not sure why this might be. This is the order they execute for me, which appears to be fine: https://i.imgur.com/2cA2cMJ.png This change should not alter any tests that have no dependencies, and those with missing dependencies could end up being pushed lower down the list, because it will be trying to add tests with existing dependencies first, before realizing that it's a cycle and no other dependencies exist, and then adding the rest in the order they remain. Overall, outside of altering the order of the tests in which they execute, there should be no downsides to this, other than some additional processing required for reordering of course. |
Just wanted to note here that since I know what this problem boils down to now (Topologically Sorting a Directed Acyclic Graph), I could try working on this more so that the resulting list is guaranteed to be stable - that is, the items aren't reordered unless absolutely necessary. The current solution is to loop through all items and only add them to the final list, if all of their dependencies have been added there already as well, which (assuming there's no cycles or missing dependencies) guarantees the correct ordering. Not sure on it's stability, but there's lots of room for improvement in terms of speed for sure. I'm marking this as a draft for the time being. |
Alright, so I think I've managed to make this one much better than it was initially. Key changes (compared to the previous version): • previous version had a theoretical desync bug between registering a dependency and adding it to the final list, that could occur in rare circumstances - most of the previous code has been replaced, so it's not the case anymore Tests pass on my side, in the same order as on the picture I sent previously (https://i.imgur.com/2cA2cMJ.png), and this thing works great on another repo of mine with 50+ tests and ~4 nesting levels of dependencies, so I'd say that it's ready to go. |
While playing with this in my test file, I discovered a bug that may still fail to reorder dependencies in some cases. Because I currently don't have an easy fix for it, I'm gonna go back to the drawing board for the time being, and probably add some proper tests for this thing too. |
This brings PR#44 up to date
This one should be ready now too. I'd like to note that since there was no response for a long time, I've moved over to |
Actually, that would be my question: if I rather tend to solve this issue by improving the documentation, explaining how to use |
For the record, |
I'd like to add that my personal use case is to test an API wrapper, which has functionality working of which is dependent on other, more basic functionality. So, if this basic functionality fails to test, testing anything dependent on it doesn't really make any sense, as they'll fail with the exact same error. Setting up this plugin seemed great at first, but then I quickly realized that it's not smart enough to test the basic functionality first (by reordering the tests), making literally the entire purpose of it absolutely obsolete. Renaming or moving around the tests (as others suggested) is not a good solution to the problem, which is why this PR exists - reordering tests is the exact thing this plugin was missing this whole time, and installing another plugin just to "cover up" missing functionality doesn't sound as a good solution either. If this is merged, or reordering based on dependencies is supported in any other way, I'm going back to this plugin in my project. |
My 2 euro cents as the maintainer of Note that I actually was about to write that I would remove the respective code from As a side note to @RKrahl: have you considered transferring this plugin to the pytest-dev organization (as I did with |
Yes, I agree. However, having test dependencies without actually making sure that those dependencies are evaluated first (by reordering the tests), kinda defeats the entire purpose of this plugin. I'm not trying to say having to use two plugins together is a bad thing, I'm just saying that in like 90% cases, the user will need to do this one way or another, unless they "solve" it with renaming or moving tests around. I'm actually surprised this isn't a feature of this plugin already, and wonder how on earth the author has managed to structure tests in their project, so that no reordering was required (unless they went with the other two approaches I mentioned). It's illogical to me that a plugin is literally useless without either special trickery or installing another plugin. Thank god that
If this would be gated behind an option, sorting could then be done from either of the two plugins. Or, if sorting would be the default here, then Again, this is really up to @RKrahl here. I think this plugin needs ordering to actually be useful to most users. If you'd be unsure, you can leave this PR open until someone finds it and gives some more feedback from their perspective, I'm fine with that. I've waited a year and a half for something to happen here, so I don't really mind waiting some more. |
I still prefer to keep the scope of the plugin focused. @DevilXD you write that So the bottom line is, if you need reordering based on dependencies, I'd recommend to use |
I'm sure there are some cases that are not covered in |
One thing is for sure and that is AFAIR documented in |
Yes, you are right. I am aware of this (or was - had already forgotten this), and this is something that I'm not sure how to handle. This makes |
I will probably go over the |
It may be a different task, but it is a part of the same feature. |
So essentially, you're saying that you've made and published this plugin with the sole purpose of helping your use case only, and anyone else who've structured their tests even a little bit out of the "natural order" you're claiming here (most likely the majority of this plugin users) is SOL and has to rely on other plugins to complete the same job? Again, this plugin is literally useless if the dependent tests aren't ran in the correct order, and in my case, the tests are logically grouped together in files, and I don't really care which order they execute in, as long as this plugin can do it's very damned purpose it's been designed for - but it doesn't. Note that I don't need any particular order these need to run in on itself, as I said, I don't care about ordering, as long as this plugin works. I don't need ordering, I need dependency. Dependency implies the dependencies are going to be ran first, otherwise you have no way of knowing if the dependent test is allowed to run or not. This plugin is literally half-done, and it seems like you're too blind to see it. sigh Can you at least put a disclaimer in README that reordering tests is not and won't be supported, and direct people to |
@DevilXD maybe https://pypi.org/project/pytest-depends (from https://gitlab.com/MaienM/pytest-depends) is what you are looking for? |
Please take the tone down a bit, ranting is not helpful and will lead nowhere. There are obviously many users that do not have this problem. You can always make a fork of this package, if it does not suit you.
|
@axel-h The topological sort it uses requires installing a whole networking library of some sorts (like, why?), and the sorting itself isn't stable, as the other person noted. My absolutely best option is to either use both this and Also to @mrbean-bremen: I'm saying the truth here - this plugin is useless if the dependencies aren't executed before dependent tests, and apparently it's author expects the programmer to work around it ourselves (by moving tests around to follow "natural order", or using another plugin). It's fine, but I think there needs to be fair warning/note placed in the README explaining this. I've had higher expectations when I first discovered this plugin, got disappointed when I learned it's not doing it's job properly, wanted to help by creating this PR, and waited a year and a half only to be disappointed even further. I simply don't want others to try it, wonder why it's not doing what they expected it to, only to learn it doesn't really work on it's own. It'd only be frustrating and a waste of time. |
You are stating your opinion. It may or may not be the same opinion as other people, especially the owner of the repo, have. It usually does not help a discussion to see an opinion as "the truth", even if you are frustrated - though that is something that seems to be the default nowadays (ranting about the discussion culture also does not help, ah well...). But I will shut up now. It is up to the owner to decide what he does with his code. |
This is probably the only thing right about your stance. |
i would like also this merged in . |
This one is based off #43, and thus includes it's changes here as well. Assuming that one would be merged, this one could be merged right after - I did it this way to properly cleanup the inconsistencies across the entire file.
The added hook function will reorder the test items based off the dependencies specified, taking into account scopes as well. There is a warning emitted for every dependency that's specified, but is not found during collection - this comes at a cost of having to process the items twice, but I think it's helpful enough to justify it.
This closes #20, and technically closes #43 too.
EDIT: Since it clearly seems that this will never be merged, please consider using pytest-order, which provides the same functionality (and more), allowing you to reorder the execution of tests, making them dependent on each other.