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

2731.bug Fix ReprFuncArgs with mixed unicode and utf-8 args. #2733

Closed
wants to merge 3 commits into from

Conversation

fgmacedo
Copy link
Contributor

The class _pytest._code.code.ReprFuncArgs crashes with UnicodeDecodeError when trying to write args with mixed unicode and utf-8 strings.

Fixes #2731.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.805% when pulling 4d6d450 on fgmacedo:fgm-fix-toterminal into 709b8b6 on pytest-dev:master.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fgmacedo!

Could you please also include a regression test similar to what you posted on the issue and a changelog entry?

@nicoddemus
Copy link
Member

For the changelog entry, I suggest a file changelog/2731.bug with the contents:

Fix ``ReprFuncArgs`` with mixed unicode and UTF-8 args.

@fgmacedo
Copy link
Contributor Author

fgmacedo commented Aug 30, 2017

Yes, for sure! Any hint for where to put the regression test? (I'm reading the test_terminal.py module).

@fgmacedo
Copy link
Contributor Author

fgmacedo commented Aug 30, 2017

Hi @nicoddemus, I think that we have reached another issue:
I've wrote the following test:

    def test_setup_fixture_error_with_mixed_encoding(self, testdir):
        testdir.makepyfile("""
            def mixed_encoding(as_unicode, as_utf8):
                assert 0
            def setup_function(function):
                mixed_encoding(u"'São Paulo'", "'S\xc3\xa3o Paulo'")
            def test_nada():
                pass
        """)
        result = testdir.runpytest()
        result.stdout.fnmatch_lines([
            "*ERROR at setup of test_nada*",
            "*setup_function(function):*",
            "*as_unicode = \"'São Paulo'\", as_utf8 = \"'São Paulo'\"*",
            "*mixed_encoding(as_unicode, as_utf8):*",
            "*assert 0*",
            "*1 error*",
        ])
        assert result.ret != 0

It works fine on Python 3.6, but fails on Python 2.7:

============================================================================= FAILURES =============================================================================
________________________________________________ TestFixtureReporting.test_setup_fixture_error_with_mixed_encoding _________________________________________________

self = <test_terminal.TestFixtureReporting object at 0x7f2d69b03f90>
testdir = <Testdir local('/tmp/pytest-of-fernando/pytest-33/testdir/test_setup_fixture_error_with_mixed_encoding0')>

    def test_setup_fixture_error_with_mixed_encoding(self, testdir):
        testdir.makepyfile("""
                def mixed_encoding(as_unicode, as_utf8):
                    assert 0
                def setup_function(function):
                    mixed_encoding(u"'São Paulo'", "'S\xc3\xa3o Paulo'")
                def test_nada():
                    pass
>           """)

/opt/loggi/pytest/testing/test_terminal.py:363: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/loggi/pytest/.tox/py27/lib/python2.7/site-packages/_pytest/pytester.py:550: in makepyfile
    return self._makefile('.py', args, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Testdir local('/tmp/pytest-of-fernando/pytest-33/testdir/test_setup_fixture_error_with_mixed_encoding0')>, ext = '.py'
args = ('\n            def mixed_encoding(as_unicode, as_utf8):\n                assert 0\n            def setup_function(fun...oding(u"\'S\xc3\xa3o Paulo\'", "\'S\xc3\xa3o Paulo\'")\n            def test_nada():\n                pass\n        ',)
kwargs = {}, encoding = 'utf-8'

    def _makefile(self, ext, args, kwargs, encoding="utf-8"):
        items = list(kwargs.items())
        if args:
            source = py.builtin._totext("\n").join(
>               map(py.builtin._totext, args)) + py.builtin._totext("\n")
E           UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 156: ordinal not in range(128)

/opt/loggi/pytest/.tox/py27/lib/python2.7/site-packages/_pytest/pytester.py:493: UnicodeDecodeError
================================================= 1 failed, 1841 passed, 61 skipped, 13 xfailed in 187.53 seconds ==================================================
ERROR: InvocationError: '/opt/loggi/pytest/.tox/py27/bin/pytest --lsof -rfsxX testing'

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.805% when pulling 09c314b on fgmacedo:fgm-fix-toterminal into 709b8b6 on pytest-dev:master.

@fgmacedo
Copy link
Contributor Author

Closing this in favor of #2735

@fgmacedo fgmacedo closed this Aug 30, 2017
@fgmacedo fgmacedo deleted the fgm-fix-toterminal branch August 30, 2017 19:08
@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.805% when pulling bf854a9 on fgmacedo:fgm-fix-toterminal into 709b8b6 on pytest-dev:master.

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

Successfully merging this pull request may close these issues.

None yet

3 participants