Skip to content

Commit 54d068a

Browse files
gh-91904: Fix setting envvar PYTHONREGRTEST_UNICODE_GUARD (GH-91905)
It always failed on non-UTF-8 locale and prevented running regrtests.
1 parent 93d2801 commit 54d068a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Lib/test/libregrtest/setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import unittest
77
from test import support
8+
from test.support.os_helper import TESTFN_UNDECODABLE, FS_NONASCII
89
try:
910
import gc
1011
except ImportError:
@@ -104,10 +105,10 @@ def _test_audit_hook(name, args):
104105

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

112113

113114
def replace_stdout():

Lib/test/test_regrtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ def test_print_warning(self):
13391339
def test_unicode_guard_env(self):
13401340
guard = os.environ.get(setup.UNICODE_GUARD_ENV)
13411341
self.assertIsNotNone(guard, f"{setup.UNICODE_GUARD_ENV} not set")
1342-
if guard != "\N{SMILING FACE WITH SUNGLASSES}":
1342+
if guard.isascii():
13431343
# Skip to signify that the env var value was changed by the user;
13441344
# possibly to something ASCII to work around Unicode issues.
13451345
self.skipTest("Modified guard")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix initialization of :envvar:`PYTHONREGRTEST_UNICODE_GUARD` which prevented
2+
running regression tests on non-UTF-8 locale.

0 commit comments

Comments
 (0)