Skip to content
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

Can't override an autouse fixture ordering #3404

Closed
wimglenn opened this issue Apr 17, 2018 · 8 comments
Closed

Can't override an autouse fixture ordering #3404

wimglenn opened this issue Apr 17, 2018 · 8 comments
Labels
good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly type: docs documentation improvement, missing or needing clarification

Comments

@wimglenn
Copy link
Member

wimglenn commented Apr 17, 2018

pytest 3.5.0 on Python 3.6.5 (macOS). This result surprised me:

import pytest

d = {'k': 'v_init'}

@pytest.fixture(autouse=True)
def fixauto(monkeypatch):
    monkeypatch.setitem(d, 'k', 'v_auto')

@pytest.fixture
def fix(monkeypatch):
    monkeypatch.setitem(d, 'k', 'v_fix')

def test_auto():
    assert d['k'] == 'v_auto'

def test_fix(fix):
    assert d['k'] == 'v_fix'

def test_fixauto_fix(fixauto, fix):
    assert d['k'] == 'v_fix'

def test_fix_fixauto(fix, fixauto):
    assert d['k'] == 'v_auto'

To be clear, first 3 tests are passing OK but the test_fix_fixauto fails. I would have expected that explicitly injecting an autouse fixture could be used to override the usual order. Feature or bug?

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Apr 17, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #3225 (A fixture with autouse set to False will always be used if it overrides a fixture with autouse set to True), #1601 (Overriding autouse fixture with a parametrized fixture does not work), #1216 (Provide a way to nicely control fixture execution order ), #668 (autouse fixtures break scope rules), and #336 (pytest-2.4.0.dev7 crashes with some autouse fixtures).

@RonnyPfannschmidt
Copy link
Member

autouse fixture are always considered before fixtures that are named, so it doesn't matter in which way you order them on a function, the autouse flag takes precedence over the order in the function call

@RonnyPfannschmidt RonnyPfannschmidt added type: question general question, might be closed after 2 weeks of inactivity type: docs documentation improvement, missing or needing clarification and removed type: bug problem that needs to be addressed labels Apr 17, 2018
@nicoddemus
Copy link
Member

@wimglenn can we close this or do we still need address something?

@RonnyPfannschmidt
Copy link
Member

we should review if the docs on this are clear enough, but otherwise i believe there is nothing we can do

@Zac-HD Zac-HD added good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly and removed type: question general question, might be closed after 2 weeks of inactivity labels Oct 19, 2018
wojtekerbetowski added a commit to wojtekerbetowski/pytest that referenced this issue Jul 13, 2019
A case with a fixture use both as an autouse and explititly
was raised. This case sounds too narrow to add to documentation
(and could be misleading for people learning pytest with explicitely
using an autouse fixture). At the same time there was no documentation
on the autouse vs regular fixture order, therefore this commit adds
such an information. Code sample grew and it was extracted to the file.
The-Compiler added a commit that referenced this issue Jul 13, 2019
Add autouse fixture order information (#3404).
@nnrepos
Copy link
Contributor

nnrepos commented Nov 2, 2019

@wojtekerbetowski, @The-Compiler do you plan on fixing that last commit or should I try to change the docs myself?

@wojtekerbetowski
Copy link
Contributor

@nnrepos @The-Compiler - I'm not sure whether I understand the prolem. Is this the coverage on an added test example? What is the rule here? Should examples be excluded from codecov, or executed during that part of the build?

@The-Compiler
Copy link
Member

@nnrepos I don't follow - what's there to fix?

@symonk
Copy link
Member

symonk commented May 31, 2020

@bluetech ok to close this ? My PR was deemed unnecessary so I think we have no doc or code changes to do here 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly type: docs documentation improvement, missing or needing clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants