Skip to content

Commit 655df7f

Browse files
authored
Merge pull request pytest-dev#1755 from diegorusso/master
Testcase for overriding autouse fixture with a parametrized fixture.
2 parents 018acc6 + 1704b7d commit 655df7f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Dave Hunt
3434
David Díaz-Barquero
3535
David Mohr
3636
David Vierra
37+
Diego Russo
3738
Edison Gustavo Muenz
3839
Eduardo Schettino
3940
Elizaveta Shashkova

testing/python/fixture.py

+32
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,38 @@ def test_spam(spam):
336336
result = testdir.runpytest(testfile)
337337
result.stdout.fnmatch_lines(["*3 passed*"])
338338

339+
def test_override_autouse_fixture_with_parametrized_fixture_conftest_conftest(self, testdir):
340+
"""Test override of the autouse fixture with parametrized one on the conftest level.
341+
This test covers the issue explained in issue 1601
342+
"""
343+
testdir.makeconftest("""
344+
import pytest
345+
346+
@pytest.fixture(autouse=True)
347+
def spam():
348+
return 'spam'
349+
""")
350+
subdir = testdir.mkpydir('subdir')
351+
subdir.join("conftest.py").write(_pytest._code.Source("""
352+
import pytest
353+
354+
@pytest.fixture(params=[1, 2, 3])
355+
def spam(request):
356+
return request.param
357+
"""))
358+
testfile = subdir.join("test_spam.py")
359+
testfile.write(_pytest._code.Source("""
360+
params = {'spam': 1}
361+
362+
def test_spam(spam):
363+
assert spam == params['spam']
364+
params['spam'] += 1
365+
"""))
366+
result = testdir.runpytest()
367+
result.stdout.fnmatch_lines(["*3 passed*"])
368+
result = testdir.runpytest(testfile)
369+
result.stdout.fnmatch_lines(["*3 passed*"])
370+
339371
def test_autouse_fixture_plugin(self, testdir):
340372
# A fixture from a plugin has no baseid set, which screwed up
341373
# the autouse fixture handling.

0 commit comments

Comments
 (0)