Skip to content

Invalid unicode in _pytest/terminal.py with Jython #5256

@fabioz

Description

@fabioz

With: Jython 2.7.1 and pytest 4.5.0, I'm having the error below:

Traceback (most recent call last):
  File "C:\bin\jython2.7.1\Lib\runpy.py", line 161, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\bin\jython2.7.1\Lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\bin\jython2.7.1\Lib\site-packages\pytest.py", line 101, in <module>
    raise SystemExit(pytest.main())
  File "C:\bin\jython2.7.1\Lib\site-packages\_pytest\config\__init__.py", line 60, in main
    config = _prepareconfig(args, plugins)
  File "C:\bin\jython2.7.1\Lib\site-packages\_pytest\config\__init__.py", line 60, in main
    config = _prepareconfig(args, plugins)
  File "C:\bin\jython2.7.1\Lib\site-packages\_pytest\config\__init__.py", line 60, in main
    config = _prepareconfig(args, plugins)
  File "C:\bin\jython2.7.1\Lib\site-packages\_pytest\config\__init__.py", line 190, in _prepareconfig
    config = get_config(args)
  File "C:\bin\jython2.7.1\Lib\site-packages\_pytest\config\__init__.py", line 164, in get_config
    pluginmanager.import_plugin(spec)
  File "C:\bin\jython2.7.1\Lib\site-packages\_pytest\config\__init__.py", line 562, in import_plugin
    __import__(importspec)
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 2-8: illegal Unicode character

The error happens because terminal._get_line_with_reprcrash_message has the following unicode literal: u"\uD83D".

I'm not sure about the proper fix... in that function msg seems to be doing a msg.find("\n") and later does msg.rstrip(u"\uD83D"), so, I'm not even sure if we're dealing with unicode or bytes there on Python 2 because it's mixed (my guess is bytes, but I'm not really sure).

If it's bytes, doing it an actual str literal instead of a unicode literal -- i.e.: remove the u -- does make Jython happy (would that be an appropriate solution?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions