pytest-dev / pytest-dev/pytest

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

Open
#7,786 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

$ 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with LANG=C pytest t.py, using the test from #7781 as the starting point. Trace how pytest sets PYTEST_CURRENT_TEST; done means the test no longer raises UnicodeEncodeError during setup or teardown when its name cannot be encoded by the current locale.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.