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

UnicodeDecodeError from pytest if object representation contains non-ascii, utf8 encoded, characters #877

Closed
magopian opened this issue Jul 25, 2015 · 2 comments

Comments

@magopian
Copy link
Contributor

Given the following test code:

    def test_foobar(self):
        class Foo(object):
            name = u'é'

            def __repr__(self):
                return self.name.encode('utf8')

        foo = Foo()
        assert not foo

Running it gives

Traceback (most recent call last):
  File "/Users/mathieu/olympia/apps/addons/tests/test_models.py", line 529, in test_foobar
    assert not foo
  File "/Users/mathieu/.virtualenvs/olympia/lib/python2.7/site-packages/_pytest/assertion/util.py", line 33, in format_explanation
    return u('\n').join(result)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 11: ordinal not in range(128)

result is ['assert not \xc3\xa9']. I believe that python's default encoding used to decode from str to unicode is ascii, which fails while decoding the utf-8 encoded object representation.

RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Jul 25, 2015
i decided against using a warning since the problem goes away with python3
the support code can be removed once we drop python2 in 10 years or so
@alvinchow86
Copy link

i'm seeing this issue too. FYI this is a duplicate of #678

RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Sep 13, 2015
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Sep 13, 2015
i decided against using a warning since the problem goes away with python3
the support code can be removed once we drop python2 in 10 years or so
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Sep 13, 2015
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Sep 18, 2015
@alvinchow86
Copy link

@RonnyPfannschmidt I did a similar fix here https://github.com/pytest-dev/pytest/compare/master...doordash:unicode-fix?expand=1, but I recall having to also fix some things in _format_lines() as well.

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

3 participants