address issue122 -- explode "params" into a list in fixture function decorators

This commit is contained in:
holger krekel 2013-12-09 10:48:15 +01:00
parent 5c3d692008
commit 7766526992
3 changed files with 34 additions and 2 deletions

View File

@ -64,6 +64,9 @@ Unreleased
- fix issue380 by making --resultlog only rely on longrepr instead - fix issue380 by making --resultlog only rely on longrepr instead
of the "reprcrash" attribute which only exists sometimes. of the "reprcrash" attribute which only exists sometimes.
- address issue122: allow @pytest.fixture(params=iterator) by exploding
into a list early on.
- fix pexpect-3.0 compatibility for pytest's own tests. - fix pexpect-3.0 compatibility for pytest's own tests.
(fixes issue386) (fixes issue386)

View File

@ -76,8 +76,9 @@ def fixture(scope="function", params=None, autouse=False):
# direct decoration # direct decoration
return FixtureFunctionMarker( return FixtureFunctionMarker(
"function", params, autouse)(scope) "function", params, autouse)(scope)
else: if params is not None and not isinstance(params, (list, tuple)):
return FixtureFunctionMarker(scope, params, autouse) params = list(params)
return FixtureFunctionMarker(scope, params, autouse)
def yield_fixture(scope="function", params=None, autouse=False): def yield_fixture(scope="function", params=None, autouse=False):
""" (return a) decorator to mark a yield-fixture factory function """ (return a) decorator to mark a yield-fixture factory function

View File

@ -914,6 +914,34 @@ class TestFixtureUsages:
reprec = testdir.inline_run() reprec = testdir.inline_run()
reprec.assertoutcome(passed=1) reprec.assertoutcome(passed=1)
def test_fixture_parametrized_with_iterator(self, testdir):
testdir.makepyfile("""
import pytest
l = []
def f():
yield 1
yield 2
dec = pytest.fixture(scope="module", params=f())
@dec
def arg(request):
return request.param
@dec
def arg2(request):
return request.param
def test_1(arg):
l.append(arg)
def test_2(arg2):
l.append(arg2*10)
""")
reprec = testdir.inline_run("-v")
reprec.assertoutcome(passed=4)
l = reprec.getcalls("pytest_runtest_call")[0].item.module.l
assert l == [1,2, 10,20]
class TestFixtureManagerParseFactories: class TestFixtureManagerParseFactories:
def pytest_funcarg__testdir(self, request): def pytest_funcarg__testdir(self, request):
testdir = request.getfuncargvalue("testdir") testdir = request.getfuncargvalue("testdir")