Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError with unicode parameters in mark.parametrize #1104

Closed
dairiki opened this issue Oct 2, 2015 · 3 comments
Closed

UnicodeEncodeError with unicode parameters in mark.parametrize #1104

dairiki opened this issue Oct 2, 2015 · 3 comments

Comments

@dairiki
Copy link

dairiki commented Oct 2, 2015

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.

@nicoddemus
Copy link
Member

Thanks for the report, but this has been fixed in #1092. 😄

It would be nice if you could test it with the latest master to confirm though:

pip install git+https://github.com/pytest-dev/pytest

@dairiki
Copy link
Author

dairiki commented Oct 2, 2015

Sorry for another dup.
And yes, this appears to have been fixed in master.

Thanks!

@nicoddemus
Copy link
Member

No worries!

Cheers,
🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants