Skip to content

Commit

Permalink
gh-91904: Fix setting envvar PYTHONREGRTEST_UNICODE_GUARD (GH-91905)
Browse files Browse the repository at this point in the history
It always failed on non-UTF-8 locale and prevented running regrtests.
(cherry picked from commit 54d068a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
miss-islington and serhiy-storchaka committed Apr 25, 2022
1 parent dc31334 commit 971343e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Lib/test/libregrtest/setup.py
Expand Up @@ -5,6 +5,7 @@
import sys
import unittest
from test import support
from test.support.os_helper import TESTFN_UNDECODABLE, FS_NONASCII
try:
import gc
except ImportError:
Expand Down Expand Up @@ -105,10 +106,10 @@ def _test_audit_hook(name, args):

# Ensure there's a non-ASCII character in env vars at all times to force
# tests consider this case. See BPO-44647 for details.
os.environ.setdefault(
UNICODE_GUARD_ENV,
"\N{SMILING FACE WITH SUNGLASSES}",
)
if TESTFN_UNDECODABLE and os.supports_bytes_environ:
os.environb.setdefault(UNICODE_GUARD_ENV.encode(), TESTFN_UNDECODABLE)
elif FS_NONASCII:
os.environ.setdefault(UNICODE_GUARD_ENV, FS_NONASCII)


def replace_stdout():
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_regrtest.py
Expand Up @@ -1303,7 +1303,7 @@ def test_threading_excepthook(self):
def test_unicode_guard_env(self):
guard = os.environ.get(setup.UNICODE_GUARD_ENV)
self.assertIsNotNone(guard, f"{setup.UNICODE_GUARD_ENV} not set")
if guard != "\N{SMILING FACE WITH SUNGLASSES}":
if guard.isascii():
# Skip to signify that the env var value was changed by the user;
# possibly to something ASCII to work around Unicode issues.
self.skipTest("Modified guard")
Expand Down
@@ -0,0 +1,2 @@
Fix initialization of :envvar:`PYTHONREGRTEST_UNICODE_GUARD` which prevented
running regression tests on non-UTF-8 locale.

0 comments on commit 971343e

Please sign in to comment.