Skip to content

Commit 18d1757

Browse files
committed
Merge pull request #983 from The-Compiler/issue-979
Fix overriding of fixtures with parametrization.
2 parents c0eec5d + 1979154 commit 18d1757

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

_pytest/python.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,10 @@ def pytest_generate_tests(self, metafunc):
18301830
if fixturedef.params is not None:
18311831
func_params = getattr(getattr(metafunc.function, 'parametrize', None), 'args', [[None]])
18321832
# skip directly parametrized arguments
1833-
if argname not in func_params:
1833+
argnames = func_params[0]
1834+
if not isinstance(argnames, (tuple, list)):
1835+
argnames = [x.strip() for x in argnames.split(",") if x.strip()]
1836+
if argname not in func_params and argname not in argnames:
18341837
metafunc.parametrize(argname, fixturedef.params,
18351838
indirect=True, scope=fixturedef.scope,
18361839
ids=fixturedef.ids)

testing/python/fixture.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,26 @@ def test_issue(foo, foobar):
16141614
reprec = testdir.inline_run()
16151615
reprec.assertoutcome(passed=9)
16161616

1617+
@pytest.mark.parametrize('param_args', ["'fixt, val'", "'fixt,val'", "['fixt', 'val']", "('fixt', 'val')"])
1618+
def test_override_parametrized_fixture_issue_979(self, testdir, param_args):
1619+
"""Make sure a parametrized argument can override a parametrized fixture.
1620+
1621+
This was a regression introduced in the fix for #736.
1622+
"""
1623+
testdir.makepyfile("""
1624+
import pytest
1625+
1626+
@pytest.fixture(params=[1, 2])
1627+
def fixt(request):
1628+
return request.param
1629+
1630+
@pytest.mark.parametrize(%s, [(3, 'x'), (4, 'x')])
1631+
def test_foo(fixt, val):
1632+
pass
1633+
""" % param_args)
1634+
reprec = testdir.inline_run()
1635+
reprec.assertoutcome(passed=2)
1636+
16171637
def test_scope_session(self, testdir):
16181638
testdir.makepyfile("""
16191639
import pytest

0 commit comments

Comments
 (0)