-
Notifications
You must be signed in to change notification settings - Fork 14
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
Parameterized tests cannot be ordered #55
Comments
This is actually what is expected. The |
I will see if I can add some functionality that provides that, as it really makes sense. This may take a while though, as I'm currently busy with other stuff. |
Thanks a lot for considering! |
I just checked, but I couldn't find a version of |
I have looked at this some more, and I don't think that there is a good way to implement this, simply because it is a somewhat special case. What happens is that parametrized tests with I will leave this open to see if this is wanted by more people, and I may reconsider in this case, but at the moment I tend to not implement this behavior. |
Hello, I think I have hit a wall here with pytest-order.
This results in:
This requires the setup fixture to be setup for 9 times (exponentially more) as oposed to 3 times if the test were run as:
One would expect a "session" scoped fixture to be setup only once per session, but that is not the case when an instance of that fixture with a different parameter is needed. In that case the fixture is destroyed and the other one is setup as mentioned in pytest-dev/pytest#3161 (comment) . |
@ipfilip - thanks, this is a valid point. I still don't have a good idea how to change this, but I may get back to this. |
Thans for the reply. |
Hi, I'm bumping against the above issue now when session-scoped fixture called multiple times for the same parameter value, e.g. |
I don't know of a workaround, sorry. I looks like I have to re-visit this issue... |
no problem, I think this is understandable enough. Re-ordering tests like that (with parameterized fixture session or module scoped) goes actually against pytest design for fixture value lifecycle in some kind of ways. You would probably need to go deeper in pytest guts to figure out if that can be possible at all in "standard" pytest plugin way. Right now my workaround is to have test module-level fixture value lazy-populated cache based on the parameter set (used as the key in dict, which implies also restriction on how fixture value is produced and value set of parameters. Fixture itself would be like that: fixture_value_cache = {}
@pytest.fixture(scope="module", params=[p1, p2, .....])
def fixt_value_p(request):
param = request.param
fixt_value_cache_k = compute_key(param)
if fixt_value_cache_k not in fixture_value_cache:
fixt_v = compute_value(param)
fixture_value_cache[fixt_value_cache_k] = fixt_v
yield fixture_value_cache[fixt_value_cache_k]
# optional post-use steps pytest would keep going with its own lifecycle, but resulting fixture value is going to be one and the same object for distinct parameters set. |
Yes, that was what I was also thinking. I'm not sure yet if I'll find a good way to do this, but I see the need for a solution. |
Considering the example in pytest documentation:
https://pytest.org/en/6.2.x/example/parametrize.html#a-quick-port-of-testscenarios
If I include ordering:
I would expect this order:
But I get instead:
I have tried with --order-scope=class and --order-group-scope=class but they dont fix this.
The text was updated successfully, but these errors were encountered: