Casting fixture parameter to list at the beginning of parameter parsing.

This commit is contained in:
Victor Maryama 2019-10-12 14:33:43 +02:00
parent bad4ffc3a7
commit 1f639e2c22
3 changed files with 22 additions and 2 deletions

View File

@ -28,6 +28,7 @@ def main():
"mock",
"nose",
"requests",
"numpy",
"xmlschema",
]
},

View File

@ -1113,6 +1113,9 @@ def fixture(
``fixture_<fixturename>`` and then use
``@pytest.fixture(name='<fixturename>')``.
"""
if params is not None and not isinstance(params, (list, tuple)):
params = list(params)
fixture_function, arguments = _parse_fixture_args(
callable_or_scope,
*args,
@ -1134,8 +1137,6 @@ def fixture(
fixture_function
)
if params is not None and not isinstance(params, (list, tuple)):
params = list(params)
return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)

View File

@ -4187,3 +4187,21 @@ def test_indirect_fixture_does_not_break_scope(testdir):
)
result = testdir.runpytest()
result.assert_outcomes(passed=7)
def test_fixture_parametrization_nparray(testdir):
testdir.makepyfile(
"""
from numpy import linspace
from pytest import fixture
@fixture(params=linspace(1, 10, 10))
def value(request):
return request.param
def test_bug(value):
assert value == value
"""
)
result = testdir.runpytest()
result.assert_outcomes(passed=10)