Skip to content

Commit 8a41b26

Browse files
authored
Merge pull request #1908 from nicoddemus/parametrize-unicode-id
The "ids" argument to "parametrize" again accepts unicode strings in Python 2
2 parents b6f766a + 1e10de5 commit 8a41b26

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
3.0.3.dev0
22
==========
33

4-
*
4+
* The ``ids`` argument to ``parametrize`` again accepts ``unicode`` strings
5+
in Python 2 (`#1905`_).
6+
Thanks `@philpep`_ for the report and `@nicoddemus`_ for the PR.
57

68
*
79

@@ -12,6 +14,11 @@
1214
*
1315

1416

17+
.. _@philpep: https://github.com/philpep
18+
19+
.. _#1905: https://github.com/pytest-dev/pytest/issues/1905
20+
21+
1522
3.0.2
1623
=====
1724

_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
832832
raise ValueError('%d tests specified with %d ids' %(
833833
len(argvalues), len(ids)))
834834
for id_value in ids:
835-
if id_value is not None and not isinstance(id_value, str):
835+
if id_value is not None and not isinstance(id_value, py.builtin._basestring):
836836
msg = 'ids must be list of strings, found: %s (type: %s)'
837837
raise ValueError(msg % (saferepr(id_value), type(id_value).__name__))
838838
ids = idmaker(argnames, argvalues, idfn, ids, self.config)

testing/python/metafunc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ def func(x, y): pass
105105
ids = [x.id for x in metafunc._calls]
106106
assert ids == ["basic-abc", "basic-def", "advanced-abc", "advanced-def"]
107107

108+
def test_parametrize_and_id_unicode(self):
109+
"""Allow unicode strings for "ids" parameter in Python 2 (##1905)"""
110+
def func(x): pass
111+
metafunc = self.Metafunc(func)
112+
metafunc.parametrize("x", [1, 2], ids=[u'basic', u'advanced'])
113+
ids = [x.id for x in metafunc._calls]
114+
assert ids == [u"basic", u"advanced"]
115+
108116
def test_parametrize_with_wrong_number_of_ids(self, testdir):
109117
def func(x, y): pass
110118
metafunc = self.Metafunc(func)

0 commit comments

Comments
 (0)