8000 bpo-44647: Add a permanent Unicode-valued env var to regrtest (GH-27… · python/cpython@93d36a5 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 93d36a5

Browse files
miss-islingtonambv
andauthored
bpo-44647: Add a permanent Unicode-valued env var to regrtest (GH-27187) (#27191)
(cherry picked from commit 7915c96) Co-authored-by: Łukasz Langa <lukasz@langa.pl>
1 parent 80844d1 commit 93d36a5

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Lib/test/libregrtest/setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
setup_threading_excepthook)
1515

1616

17+
UNICODE_GUARD_ENV = "PYTHONREGRTEST_UNICODE_GUARD"
18+
19+
1720
def setup_tests(ns):
1821
try:
1922
stderr_fd = sys.__stderr__.fileno()
@@ -99,6 +102,13 @@ def _test_audit_hook(name, args):
99102
from test.support.testresult import RegressionTestResult
100103
RegressionTestResult.USE_XML = True
101104

105+
# Ensure there's a non-ASCII character in env vars at all times to force
106+
# tests consider this case. See BPO-44647 for details.
107+
os.environ.setdefault(
108+
UNICODE_GUARD_ENV,
109+
"\N{SMILING FACE WITH SUNGLASSES}",
110+
)
111+
102112

103113
def replace_stdout():
104114
"""Set stdout encoder error handler to backslashreplace (as stderr error

Lib/test/test_regrtest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from test import libregrtest
2020
from test import support
2121
from test.support import os_helper
22-
from test.libregrtest import utils
22+
from test.libregrtest import utils, setup
2323

2424

2525
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
@@ -1298,6 +1298,14 @@ def test_threading_excepthook(self):
12981298
self.assertIn("Warning -- Uncaught thread exception", output)
12991299
self.assertIn("Exception: bug in thread", output)
13001300

1301+
def test_unicode_guard_env(self):
1302+
guard = os.environ.get(setup.UNICODE_GUARD_ENV)
1303+
self.assertIsNotNone(guard, f"{setup.UNICODE_GUARD_ENV} not set")
1304+
if guard != "\N{SMILING FACE WITH SUNGLASSES}":
1305+
# Skip to signify that the env var value was changed by the user;
1306+
# possibly to something ASCII to work around Unicode issues.
1307+
self.skipTest("Modified guard")
1308+
13011309
def test_cleanup(self):
13021310
dirname = os.path.join(self.tmptestdir, "test_python_123")
13031311
os.mkdir(dirname)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Added a permanent Unicode-valued environment variable to regression tests to
2+
ensure they handle this use case in the future. If your test environment
3+
breaks because of that, report a bug to us, and temporarily set
4+
PYTHONREGRTEST_UNICODE_GUARD=0 in your test environment.

0 commit comments

Comments
 (0)
0