Merge pull request #983 from The-Compiler/issue-979

Fix overriding of fixtures with parametrization.
This commit is contained in:
Anatoly Bubenkov 2015-08-31 15:21:45 +02:00
commit 18d175708c
2 changed files with 24 additions and 1 deletions

View File

@ -1830,7 +1830,10 @@ class FixtureManager:
if fixturedef.params is not None: if fixturedef.params is not None:
func_params = getattr(getattr(metafunc.function, 'parametrize', None), 'args', [[None]]) func_params = getattr(getattr(metafunc.function, 'parametrize', None), 'args', [[None]])
# skip directly parametrized arguments # skip directly parametrized arguments
if argname not in func_params: argnames = func_params[0]
if not isinstance(argnames, (tuple, list)):
argnames = [x.strip() for x in argnames.split(",") if x.strip()]
if argname not in func_params and argname not in argnames:
metafunc.parametrize(argname, fixturedef.params, metafunc.parametrize(argname, fixturedef.params,
indirect=True, scope=fixturedef.scope, indirect=True, scope=fixturedef.scope,
ids=fixturedef.ids) ids=fixturedef.ids)

View File

@ -1614,6 +1614,26 @@ class TestFixtureMarker:
reprec = testdir.inline_run() reprec = testdir.inline_run()
reprec.assertoutcome(passed=9) reprec.assertoutcome(passed=9)
@pytest.mark.parametrize('param_args', ["'fixt, val'", "'fixt,val'", "['fixt', 'val']", "('fixt', 'val')"])
def test_override_parametrized_fixture_issue_979(self, testdir, param_args):
"""Make sure a parametrized argument can override a parametrized fixture.
This was a regression introduced in the fix for #736.
"""
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1, 2])
def fixt(request):
return request.param
@pytest.mark.parametrize(%s, [(3, 'x'), (4, 'x')])
def test_foo(fixt, val):
pass
""" % param_args)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
def test_scope_session(self, testdir): def test_scope_session(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest