Skip to content

Commit

Permalink
The "ids" argument to "parametrize" again accepts unicode strings in …
Browse files Browse the repository at this point in the history
…Python 2

Fixes pytest-dev#1905
  • Loading branch information
nicoddemus committed Sep 2, 2016
1 parent 722f9ea commit 1e10de5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
3.0.3.dev0
==========

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

*

Expand All @@ -12,6 +14,11 @@
*


.. _@philpep: https://github.com/philpep

.. _#1905: https://github.com/pytest-dev/pytest/issues/1905


3.0.2
=====

Expand Down
2 changes: 1 addition & 1 deletion _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
raise ValueError('%d tests specified with %d ids' %(
len(argvalues), len(ids)))
for id_value in ids:
if id_value is not None and not isinstance(id_value, str):
if id_value is not None and not isinstance(id_value, py.builtin._basestring):
msg = 'ids must be list of strings, found: %s (type: %s)'
raise ValueError(msg % (saferepr(id_value), type(id_value).__name__))
ids = idmaker(argnames, argvalues, idfn, ids, self.config)
Expand Down
8 changes: 8 additions & 0 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def func(x, y): pass
ids = [x.id for x in metafunc._calls]
assert ids == ["basic-abc", "basic-def", "advanced-abc", "advanced-def"]

def test_parametrize_and_id_unicode(self):
"""Allow unicode strings for "ids" parameter in Python 2 (##1905)"""
def func(x): pass
metafunc = self.Metafunc(func)
metafunc.parametrize("x", [1, 2], ids=[u'basic', u'advanced'])
ids = [x.id for x in metafunc._calls]
assert ids == [u"basic", u"advanced"]

def test_parametrize_with_wrong_number_of_ids(self, testdir):
def func(x, y): pass
metafunc = self.Metafunc(func)
Expand Down

0 comments on commit 1e10de5

Please sign in to comment.