From 885e461ae3852acead946c5cd0c674d4d6a20642 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 31 Aug 2015 14:38:39 +0200 Subject: [PATCH 1/2] Fix overriding of fixtures with parametrization. Fixes #979, see #926. --- _pytest/python.py | 5 ++++- testing/python/fixture.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/_pytest/python.py b/_pytest/python.py index 89b726dd4..9b04e7861 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1830,7 +1830,10 @@ class FixtureManager: if fixturedef.params is not None: func_params = getattr(getattr(metafunc.function, 'parametrize', None), 'args', [[None]]) # 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, indirect=True, scope=fixturedef.scope, ids=fixturedef.ids) diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 48f52d2a0..677e023f7 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -1614,6 +1614,22 @@ class TestFixtureMarker: reprec = testdir.inline_run() 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): + 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): testdir.makepyfile(""" import pytest From 19791546dac940680e1a1cb8cc88b570c6c0e892 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 31 Aug 2015 15:11:57 +0200 Subject: [PATCH 2/2] Add docstring. --- testing/python/fixture.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 677e023f7..203176443 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -1616,6 +1616,10 @@ class TestFixtureMarker: @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