From 1e10de574dc9c08c9a2af8b74380feb28da8c28b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 2 Sep 2016 18:25:26 -0300 Subject: [PATCH] The "ids" argument to "parametrize" again accepts unicode strings in Python 2 Fixes #1905 --- CHANGELOG.rst | 9 ++++++++- _pytest/python.py | 2 +- testing/python/metafunc.py | 8 ++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b7ca1973425..b3b1dda8d35 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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. * @@ -12,6 +14,11 @@ * +.. _@philpep: https://github.com/philpep + +.. _#1905: https://github.com/pytest-dev/pytest/issues/1905 + + 3.0.2 ===== diff --git a/_pytest/python.py b/_pytest/python.py index 2ab1de6b044..33e7cff66d5 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 58f56697380..b9bf589c343 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -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)