Skip to content

Can't override an autouse fixture ordering #3404

@wimglenn

Description

@wimglenn

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortopic: fixturesanything involving fixtures directly or indirectlytype: docsdocumentation improvement, missing or needing clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions