Skip to content

Order of execution of fixtures #3596

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

Closed
LexLootor opened this issue Jun 18, 2018 · 3 comments
Closed

Order of execution of fixtures #3596

LexLootor opened this issue Jun 18, 2018 · 3 comments
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity

Comments

@LexLootor
Copy link

In version of pytest 3.5.0 appeared execution of fixtures by higher scope. #3306

But I need to use autouse fixture with scope=function first, at least before fixtures with other scope and without autouse. There are any possibilities to do this?

def test_1(fixture_module):
    assert True

@pytest.fixture(autouse=True, scope="function")
def fixture_function():
    print("scope function")

@pytest.fixture(scope="module")
def fixture_module():
    print("scope module")

Code output:

scope module
scope function

pytest version 3.6.0
On version 3.2.2 this example work in this order:

scope function
scope module
@pytestbot pytestbot added the topic: fixtures anything involving fixtures directly or indirectly label Jun 18, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #805 (Fixture execution order ), #1216 (Provide a way to nicely control fixture execution order ), #2547 (unexpected fixture execution order), #2861 (Question re: order of execution of test fixtures), and #538 (Fixture scope documentation).

@nicoddemus
Copy link
Member

Hi @LexLootor,

Unfortunately I don't think there's a way to override the order, currently all functions are instantiated based on their scope.

Can you describe in more details what your fixtures do exactly? We might able to provide alternatives based on that information.

@nicoddemus nicoddemus added type: question general question, might be closed after 2 weeks of inactivity status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity labels Jun 19, 2018
@LexLootor
Copy link
Author

Hello @nicoddemus, thank you for answer.

I found solution for me in hook pytest_runtest_setup.

I think if there are no way to override the order, i can close this issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants