-
-
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
function-scoped fixture run before session-scoped fixture #5303
Comments
From what I was able to understand from the code changed in #3306, the problem is that in |
It looks like in order to solve it, a significant amount of code would need to be modified to refer to fixtures with a more fully-qualified name. @RonnyPfannschmidt @nicoddemus based on the git blame you seem to be the ones with the most intimate knowledge of this code. Any insight? |
nope, sorry |
I would always want a redefined fixture in a subdirectory to overwrite the one from the parent directory. If, for example, a test in |
Noticed this too while reviewing #11243. As @brianmaissy said, the problem is here: pytest/src/_pytest/fixtures.py Line 1558 in 9c8937b
Just using A simpler reproduction is: import pytest
@pytest.fixture(scope="module")
def whoops(): print("WHOOPS")
@pytest.fixture(scope="module")
def fix(whoops): print("MOD")
class Test:
@pytest.fixture(scope="function")
def fix(self, fix): print("FUNC")
def test(self, fix): pass The I guess |
I reported a bug in #11350 where this results in a hard error instead of just a wrong ordering |
This is a possible regression of #2405, or possibly a previously unconsidered edge case.
I have a case where a conftest in a subdirectory overrides a fixture with the same name from the enclosing directory's conftest, and this fact causes the fixtures to be set up in the wrong order (a function-scoped fixture is run before a session-scoped fixture).
Here's the example:
The root conftest:
The subdirectory conftest:
test_it.py:
The output:
As you can see, fixture_two (the autouse function-scoped fixture) is run before fixture_one, which is the session-scoped dependency of the original fixture_three (and an indirect dependency of the overridden fixture_three).
Renaming the second fixture_three solves the problem.
The text was updated successfully, but these errors were encountered: