From 7b87f7b6b518f56e289dc8d517db1b47e0b09e97 Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Tue, 10 Dec 2013 14:27:29 +0100 Subject: [PATCH] Paratrization overrides existing fixtures. --HG-- branch : override-fixture-via-parametrization --- _pytest/python.py | 2 -- testing/python/collect.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 8d75804a8..b437871a7 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -368,7 +368,6 @@ def add_funcarg_pseudo_fixture_def(collector, metafunc, fixturemanager): arg2fixturedefs = metafunc._arg2fixturedefs for param_index, callspec in enumerate(metafunc._calls): for argname, argvalue in callspec.funcargs.items(): - assert argname not in arg2fixturedefs arg2params.setdefault(argname, []).append(argvalue) if argname not in arg2scope: scopenum = callspec._arg2scopenum.get(argname, scopenum_function) @@ -387,7 +386,6 @@ def add_funcarg_pseudo_fixture_def(collector, metafunc, fixturemanager): # to make sure we only ever create an according fixturedef on # a per-scope basis. We thus store and cache the fixturedef on the # node related to the scope. - assert argname not in arg2fixturedefs, (argname, arg2fixturedefs) scope = arg2scope[argname] node = None if scope != "function": diff --git a/testing/python/collect.py b/testing/python/collect.py index ac3892db3..381f68797 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -372,6 +372,24 @@ class TestFunction: rec.assertoutcome(passed=2) + def test_parametrize_overrides_fixture(self, testdir): + """Test parametrization when parameter overrides existing fixture with same name.""" + testdir.makepyfile(""" + import pytest + + @pytest.fixture + def value(): + return 'value' + + @pytest.mark.parametrize('value', + ['overrided']) + def test_overrided_via_param(value): + assert value == 'overrided' + """) + rec = testdir.inline_run() + rec.assertoutcome(passed=1) + + def test_parametrize_with_mark(selfself, testdir): items = testdir.getitems(""" import pytest