Skip to content

pytest fails setting PYTEST_CURRENT_TEST when test name cannot be encoded with current locale  #7786

@asottile

Description

@asottile
$ LANG=C pytest t.py 
============================= test session starts ==============================
platform linux -- Python 3.6.12, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: /tmp/x/pytest, configfile: pyproject.toml
plugins: hypothesis-5.35.4
collected 1 item                                                               

t.py EE                                                                  [100%]

==================================== ERRORS ====================================
\x1b[31m\x1b[1m______________________ ERROR at setup of test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 _______________________\x1b[0m

self = environ({'LANG': 'C', 'SHELL': '/bin/bash', 'SESSION_MANAGER': 'local/babibox:@/tmp/.ICE-unix/1669,unix/babibox:/tmp/....DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus', 'OLDPWD': '/tmp/x', '_': '/tmp/x/pytest/venv36/bin/pytest'})
key = b'PYTEST_CURRENT_TEST', value = 't.py::test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 (setup)'

    def __setitem__(self, key, value):
        key = self.encodekey(key)
>       value = self.encodevalue(value)

/usr/lib/python3.6/os.py:674: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

value = 't.py::test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 (setup)'

    def encode(value):
        if not isinstance(value, str):
            raise TypeError("str expected, not %s" % type(value).__name__)
>       return value.encode(encoding, 'surrogateescape')
E       UnicodeEncodeError: 'ascii' codec can't encode characters in position 12-15: ordinal not in range(128)

/usr/lib/python3.6/os.py:745: UnicodeEncodeError
\x1b[31m\x1b[1m_____________________ ERROR at teardown of test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 _____________________\x1b[0m

self = environ({'LANG': 'C', 'SHELL': '/bin/bash', 'SESSION_MANAGER': 'local/babibox:@/tmp/.ICE-unix/1669,unix/babibox:/tmp/....DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus', 'OLDPWD': '/tmp/x', '_': '/tmp/x/pytest/venv36/bin/pytest'})
key = b'PYTEST_CURRENT_TEST', value = 't.py::test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 (teardown)'

    def __setitem__(self, key, value):
        key = self.encodekey(key)
>       value = self.encodevalue(value)

/usr/lib/python3.6/os.py:674: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

value = 't.py::test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 (teardown)'

    def encode(value):
        if not isinstance(value, str):
            raise TypeError("str expected, not %s" % type(value).__name__)
>       return value.encode(encoding, 'surrogateescape')
E       UnicodeEncodeError: 'ascii' codec can't encode characters in position 12-15: ordinal not in range(128)

/usr/lib/python3.6/os.py:745: UnicodeEncodeError
=========================== short test summary info ============================
ERROR t.py::test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 - UnicodeEncodeError: 'ascii' codec can't encode ...
ERROR t.py::test4_\u0447\u045b\u0448\u0452_\u010d\u0107\u0161\u0111 - UnicodeEncodeError: 'ascii' codec can't encode ...
============================== 2 errors in 0.21s ===============================

Using the test from #7781

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: 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