Fix encoding errors for parametrized tests with unicode parameters in py2

Fix #1085
This commit is contained in:
Bruno Oliveira 2015-09-29 17:57:49 -03:00
parent e9240f7eee
commit 8633c4cefd
2 changed files with 20 additions and 1 deletions

View File

@ -1093,7 +1093,7 @@ def _idval(val, argname, idx, idfn):
# convertible to ascii, return it as an str() object instead # convertible to ascii, return it as an str() object instead
try: try:
return str(val) return str(val)
except UnicodeDecodeError: except UnicodeError:
# fallthrough # fallthrough
pass pass
return str(argname)+str(idx) return str(argname)+str(idx)

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import re import re
import pytest, py import pytest, py
@ -118,6 +119,24 @@ class TestMetafunc:
assert metafunc._calls[2].id == "x1-a" assert metafunc._calls[2].id == "x1-a"
assert metafunc._calls[3].id == "x1-b" assert metafunc._calls[3].id == "x1-b"
@pytest.mark.skipif('sys.version_info[0] >= 3')
def test_unicode_idval_python2(self):
"""unittest for the expected behavior to obtain ids for parametrized
unicode values in Python 2: if convertible to ascii, they should appear
as ascii values, otherwise fallback to hide the value behind the name
of the parametrized variable name. #1086
"""
from _pytest.python import _idval
values = [
(u'', ''),
(u'ascii', 'ascii'),
(u'ação', 'a6'),
(u'josé@blah.com', 'a6'),
(u'δοκ.ιμή@παράδειγμα.δοκιμή', 'a6'),
]
for val, expected in values:
assert _idval(val, 'a', 6, None) == expected
@pytest.mark.issue250 @pytest.mark.issue250
def test_idmaker_autoname(self): def test_idmaker_autoname(self):
from _pytest.python import idmaker from _pytest.python import idmaker