Skip to content

Commit ab308bc

Browse files
author
Sylvain MARIE
committed
Fixed error message related to misuse of fixture_ref. Fixes #209
1 parent 97356f0 commit ab308bc

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

pytest_cases/fixture_core1_unions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def __init__(self, params):
156156
self.params = params
157157

158158
def __str__(self):
159-
return "Invalid parameters list (`argvalues`) in pytest parametrize: %s" % self.params
159+
return "Invalid parameters list (`argvalues`) in pytest parametrize. `list(argvalues)` returned an error. " \
160+
"Please make sure that `argvalues` is a list, tuple or iterable : %r" % self.params
160161

161162

162163
def is_fixture_union_params(params):

pytest_cases/fixture_parametrize_plus.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ def __repr__(self):
162162
def _check_iterable(self):
163163
"""Raise a TypeError if this fixture reference is not iterable, that is, it does not represent a tuple"""
164164
if self.theoretical_size is None:
165-
raise TypeError("This fixture_ref has not yet been initialized")
165+
raise TypeError("This `fixture_ref` has not yet been initialized, so it cannot be unpacked/iterated upon. "
166+
"This is not supposed to happen when a `fixture_ref` is used correctly, i.e. as an item in"
167+
" the `argvalues` of a `@parametrize` decorator. Please check the documentation for "
168+
"details.")
166169
if self.theoretical_size == 1:
167170
raise TypeError("This fixture_ref does not represent a tuple of arguments, it is not iterable")
168171

pytest_cases/tests/pytest_extension/parametrize_plus/test_fixture_ref_basic1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE>
55
import pytest
6+
7+
from pytest_cases.fixture_core1_unions import InvalidParamsList
68
from pytest_cases import fixture, fixture_ref, parametrize
79
from pytest_cases.tests.conftest import global_fixture
810

@@ -49,3 +51,11 @@ def c():
4951
def test_foo(a, b):
5052
"""here the fixture is used for both parameters at the same time"""
5153
assert (a, b) == (3, 2)
54+
55+
56+
def test_invalid_argvalues_message():
57+
""" Check that the error message is friendly when the fixture_ref is misused"""
58+
with pytest.raises(InvalidParamsList) as exc_info:
59+
parametrize("fixture_a", fixture_ref('a'))
60+
assert str(exc_info.value).startswith("Invalid parameters list (`argvalues`) in pytest parametrize. "
61+
"`list(argvalues)` returned an error.")

0 commit comments

Comments
 (0)