Skip to content

Escape unencodable names in PYTEST_CURRENT_TEST - #15197

Open
jinchuntan wants to merge 1 commit into
pytest-dev:mainfrom
jinchuntan:fix/current-test-env-encoding
Open

jinchuntan wants to merge 1 commit into
pytest-dev:mainfrom
jinchuntan:fix/current-test-env-encoding

Conversation

@jinchuntan

Copy link
Copy Markdown

Tests with Unicode names can now run when the environment cannot encode them. If setting PYTEST_CURRENT_TEST raises UnicodeEncodeError pytest retries with readable backslash escapes using the environment encoding.

This follows the encoding concerns discussed in #7787. A child process using the same locale can read the value.

Added subprocess regressions for ASCII and UTF8 modes. They check all three test phases plus cleanup and the inherited value. The new cases require zero warnings.

Validated with the full Python 3.13 suite and the runner suite on Python 3.10 and Python 3.15rc3. The full run has no failing tests. All project lint checks pass.

Fixes #7786

Prepared with Codex assistance.

A Unicode test name can stop setup and teardown when pytest sets
PYTEST_CURRENT_TEST under an ASCII locale.

Retry a failed environment assignment with readable backslash escapes
using the filesystem encoding. Another process under the same locale
can read the value.

Add subprocess coverage for ASCII and UTF8 modes through all test
phases and environment cleanup.

Fixes pytest-dev#7786

Co-authored-by: Codex <noreply@openai.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant