Skip to content

UnicodeEncodeError with unicode parameters in mark.parametrize #1104

Closed
@dairiki

Description

@dairiki

With python2 (2.6 & 2.7), pytest 2.8.1, and the following in test_u.py

import pytest

@pytest.mark.parametrize('euro', u'\u20ac')
def test_one(euro):
    pass

py.test test_u.py fails with

============================= test session starts ==============================
platform linux2 -- Python 2.7.3, pytest-2.8.1, py-1.4.30, pluggy-0.3.1
rootdir: /srv/w/users/dairiki/git/discnw/btp_buildout, inifile: pytest.ini
collected 0 items / 1 errors 

==================================== ERRORS ====================================
_______________________ ERROR collecting junk/test_u.py ________________________
py27/local/lib/python2.7/site-packages/_pytest/runner.py:149: in __init__
    self.result = func()
py27/local/lib/python2.7/site-packages/_pytest/main.py:437: in _memocollect
    return self._memoizedcall('_collected', lambda: list(self.collect()))
py27/local/lib/python2.7/site-packages/_pytest/main.py:317: in _memoizedcall
    res = function()
py27/local/lib/python2.7/site-packages/_pytest/main.py:437: in <lambda>
    return self._memoizedcall('_collected', lambda: list(self.collect()))
py27/local/lib/python2.7/site-packages/_pytest/python.py:578: in collect
    return super(Module, self).collect()
py27/local/lib/python2.7/site-packages/_pytest/python.py:432: in collect
    res = self.makeitem(name, obj)
py27/local/lib/python2.7/site-packages/_pytest/python.py:444: in makeitem
    collector=self, name=name, obj=obj)
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:724: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:338: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:333: in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:595: in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:249: in _wrapped_call
    wrap_controller.send(call_outcome)
py27/local/lib/python2.7/site-packages/_pytest/python.py:307: in pytest_pycollect_makeitem
    res = list(collector._genfunctions(name, obj))
py27/local/lib/python2.7/site-packages/_pytest/python.py:464: in _genfunctions
    self.ihook.pytest_generate_tests(metafunc=metafunc)
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:724: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:338: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:333: in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
py27/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:596: in execute
    res = hook_impl.function(*args)
py27/local/lib/python2.7/site-packages/_pytest/python.py:217: in pytest_generate_tests
    metafunc.parametrize(*marker.args, **marker.kwargs)
py27/local/lib/python2.7/site-packages/_pytest/python.py:994: in parametrize
    ids = idmaker(argnames, argvalues, idfn)
py27/local/lib/python2.7/site-packages/_pytest/python.py:1108: in idmaker
    for valindex, valset in enumerate(argvalues)]
py27/local/lib/python2.7/site-packages/_pytest/python.py:1103: in _idvalset
    for val, argname in zip(valset, argnames)]
py27/local/lib/python2.7/site-packages/_pytest/python.py:1095: in _idval
    return str(val)
E   UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 0: ordinal not in range(128)
=========================== 1 error in 0.47 seconds ============================

This does not happen with pytest==2.8.0 and does not seem to be an issue in py3k.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions