-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Question re: order of execution of test fixtures #2861
Comments
Currently all autouse fixtures in a node are executed first. You can see this here: Lines 1004 to 1032 in 531e0dc
There's no way to override this behavior currently, I'm afraid. |
Thanks for confirming. Luckily I found a way to break the dependencies between my auto-used fixtures and the non-auto-used ones, so as to avoid the problem I was having. However, it would be nice if there were some way to reprioritize the execution order of the fixtures somehow. Given that I no longer have an applicable use case, I'll leave that up to your project maintainers to decide whether that's something worth investigating or not. Thanks again for your help. |
Good day.
This is probably more of a question than a bug, but I'm curious if there are any docs describing the order of execution of test fixtures in pytest?
Specifically, I have the following use case / problem: I have 3 test fixtures I'm trying to organize:
Now, most of this use case is pretty easy to orchestrate but here's where my problem lies. For tests that use fixture3, I need the 3 fixtures to run in the following order: fixture2, fixture1, fixture3. I can't seem to find a solution that ensures this order of execution whilst using the auto-use flag for fixture1. In every case fixture1 always runs first. Can someone perhaps explain what I might be doing wrong or how to get the desired behavior?
Here's a snippet of code that illustrates what my current implementation looks like:
The closest solution I found to get the desired behavior is to disable the autouse flag on fixture1 (aka: config_test_logger) and add an explicit dependency on this fixtures to fixture3 (aka: test_env) like this:
This slight variation has the benefit of ensuring the order of execution of the fixtures is correct (ie: fixture2, fixture1, fixture3) but has the down side of requiring every other unit test in the suite to explicitly mark a dependency on fixture1, which is overly verbose and fragile at best.
I've also tried several variations of this including explicitly listing
config_test_logger
as a dependent fixture intest_env
and leaving theautouse
flag enabled on the former, renaming the fixture methods so they follow an alphabetical ordering (ie:a_setup_env
,b_test_env
,c_config_test_logger
) just in case the ordering was alphabetic, and several other things but I can't seem to find a solution that gets me exactly what I'm looking for.Any help anyone has would be greatly appreciated.
The text was updated successfully, but these errors were encountered: