Skip to content

Commit

Permalink
support override of the parametrized fixture on the test level
Browse files Browse the repository at this point in the history
--HG--
branch : parametrized-fixture-override
  • Loading branch information
bubenkoff committed Mar 1, 2015
1 parent 0606093 commit c462393
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,9 +1716,12 @@ def pytest_generate_tests(self, metafunc):
continue # will raise FixtureLookupError at setup time
for fixturedef in faclist[-1:]:
if fixturedef.params is not None:
metafunc.parametrize(argname, fixturedef.params,
indirect=True, scope=fixturedef.scope,
ids=fixturedef.ids)
func_params = getattr(getattr(metafunc.function, 'parametrize', None), 'args', [[None]])
# skip directly parametrized arguments
if argname not in func_params and argname not in func_params[0]:
metafunc.parametrize(argname, fixturedef.params,
indirect=True, scope=fixturedef.scope,
ids=fixturedef.ids)

def pytest_collection_modifyitems(self, items):
# separate parametrized setups
Expand Down
17 changes: 17 additions & 0 deletions testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,23 @@ def test_overrided_via_param(value):
rec.assertoutcome(passed=1)


def test_parametrize_overrides_parametrized_fixture(self, testdir):
"""Test parametrization when parameter overrides existing parametrized fixture with same name."""
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1, 2])
def value(request):
return request.param
@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
Expand Down

0 comments on commit c462393

Please sign in to comment.