Skip to content

Commit 971343e

Browse files
gh-91904: Fix setting envvar PYTHONREGRTEST_UNICODE_GUARD (GH-91905)
It always failed on non-UTF-8 locale and prevented running regrtests. (cherry picked from commit 54d068a) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent dc31334 commit 971343e

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:
@@ -105,10 +106,10 @@ def _test_audit_hook(name, args):
105106

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

113114

114115
def replace_stdout():

Lib/test/test_regrtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ def test_threading_excepthook(self):
13031303
def test_unicode_guard_env(self):
13041304
guard = os.environ.get(setup.UNICODE_GUARD_ENV)
13051305
self.assertIsNotNone(guard, f"{setup.UNICODE_GUARD_ENV} not set")
1306-
if guard != "\N{SMILING FACE WITH SUNGLASSES}":
1306+
if guard.isascii():
13071307
# Skip to signify that the env var value was changed by the user;
13081308
# possibly to something ASCII to work around Unicode issues.
13091309
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)