Merged in paylogic/pytest/override-fixture-via-parametrization (pull request #92)
Paratrization overrides existing fixtures.
This commit is contained in:
commit
9cdb6fc724
|
@ -368,7 +368,6 @@ def add_funcarg_pseudo_fixture_def(collector, metafunc, fixturemanager):
|
||||||
arg2fixturedefs = metafunc._arg2fixturedefs
|
arg2fixturedefs = metafunc._arg2fixturedefs
|
||||||
for param_index, callspec in enumerate(metafunc._calls):
|
for param_index, callspec in enumerate(metafunc._calls):
|
||||||
for argname, argvalue in callspec.funcargs.items():
|
for argname, argvalue in callspec.funcargs.items():
|
||||||
assert argname not in arg2fixturedefs
|
|
||||||
arg2params.setdefault(argname, []).append(argvalue)
|
arg2params.setdefault(argname, []).append(argvalue)
|
||||||
if argname not in arg2scope:
|
if argname not in arg2scope:
|
||||||
scopenum = callspec._arg2scopenum.get(argname, scopenum_function)
|
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
|
# to make sure we only ever create an according fixturedef on
|
||||||
# a per-scope basis. We thus store and cache the fixturedef on the
|
# a per-scope basis. We thus store and cache the fixturedef on the
|
||||||
# node related to the scope.
|
# node related to the scope.
|
||||||
assert argname not in arg2fixturedefs, (argname, arg2fixturedefs)
|
|
||||||
scope = arg2scope[argname]
|
scope = arg2scope[argname]
|
||||||
node = None
|
node = None
|
||||||
if scope != "function":
|
if scope != "function":
|
||||||
|
|
|
@ -372,6 +372,24 @@ class TestFunction:
|
||||||
rec.assertoutcome(passed=2)
|
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):
|
def test_parametrize_with_mark(selfself, testdir):
|
||||||
items = testdir.getitems("""
|
items = testdir.getitems("""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
Loading…
Reference in New Issue