Sort fixtures by scope when determining fixture closure

Fix #2405
This commit is contained in:
Bruno Oliveira
2018-03-13 21:08:21 -03:00
parent 9e24b09a9f
commit 59e7fd478e
5 changed files with 277 additions and 16 deletions

View File

@@ -964,3 +964,27 @@ def test_fixture_values_leak(testdir):
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines(['* 2 passed *'])
def test_fixture_order_respects_scope(testdir):
"""Ensure that fixtures are created according to scope order, regression test for #2405
"""
testdir.makepyfile('''
import pytest
data = {}
@pytest.fixture(scope='module')
def clean_data():
data.clear()
@pytest.fixture(autouse=True)
def add_data():
data.update(value=True)
@pytest.mark.usefixtures('clean_data')
def test_value():
assert data.get('value')
''')
result = testdir.runpytest()
assert result.ret == 0