Skip to content

Commit 3d7e97a

Browse files
committed
adjust test_parametrized_ids_invalid_type, create list to convert tuples
Ref: pytest-dev#1857 (comment)
1 parent ef12faa commit 3d7e97a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/_pytest/python.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ def _resolve_arg_ids(self, argnames, ids, parameters, item):
10301030

10311031
def _validate_ids(self, ids, parameters, func_name):
10321032
try:
1033-
len_ids = len(ids)
1033+
len(ids)
10341034
except TypeError:
10351035
try:
10361036
it = iter(ids)
@@ -1039,13 +1039,13 @@ def _validate_ids(self, ids, parameters, func_name):
10391039
else:
10401040
import itertools
10411041

1042-
ids = list(itertools.islice(it, len(parameters)))
1043-
len_ids = len(ids)
1042+
new_ids = list(itertools.islice(it, len(parameters)))
1043+
else:
1044+
new_ids = list(ids)
10441045

1045-
if len_ids != len(parameters):
1046+
if len(new_ids) != len(parameters):
10461047
msg = "In {}: {} parameter sets specified, with different number of ids: {}"
10471048
fail(msg.format(func_name, len(parameters), len(ids)), pytrace=False)
1048-
new_ids = ids[:]
10491049
for idx, id_value in enumerate(new_ids):
10501050
if id_value is not None:
10511051
if isinstance(id_value, int):

testing/python/metafunc.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1186,20 +1186,21 @@ def test_temp(temp):
11861186
result.stdout.fnmatch_lines(["* 1 skipped *"])
11871187

11881188
def test_parametrized_ids_invalid_type(self, testdir):
1189-
"""Tests parametrized with ids as non-strings (#1857)."""
1189+
"""Test error with non-strings/non-ints, without generator (#1857)."""
11901190
testdir.makepyfile(
11911191
"""
11921192
import pytest
11931193
1194-
@pytest.mark.parametrize("x, expected", [(10, 20), (40, 80)], ids=(None, 2))
1194+
@pytest.mark.parametrize("x, expected", [(1, 2), (3, 4), (5, 6)], ids=(None, 2, type))
11951195
def test_ids_numbers(x,expected):
11961196
assert x * 2 == expected
11971197
"""
11981198
)
11991199
result = testdir.runpytest()
12001200
result.stdout.fnmatch_lines(
12011201
[
1202-
"*In test_ids_numbers: ids must be list of strings, found: 2 (type: *'int'>)*"
1202+
"In test_ids_numbers: ids must be list of strings, "
1203+
"found: <class 'type'> (type: <class 'type'>) at index 2"
12031204
]
12041205
)
12051206

0 commit comments

Comments
 (0)