Casting fixture parameter to list at the beginning of parameter… (#5950)

Casting fixture parameter to list at the beginning of parameter parsing.
This commit is contained in:
Bruno Oliveira 2019-10-12 17:02:48 -03:00 committed by GitHub
commit 3322c1e033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 2 deletions

View File

@ -0,0 +1 @@
Fixed issue when parametrizing fixtures with numpy arrays (and possibly other sequence-like types).

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:
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)