bpo-44647: Add a permanent Unicode-valued env var to regrtest (GH-27187) (#27191)
(cherry picked from commit 7915c96ffd7ddc5cb6d54015ee4c31255a416892)
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py
index 83ce2f7..472c6eb 100644
--- a/Lib/test/libregrtest/setup.py
+++ b/Lib/test/libregrtest/setup.py
@@ -14,6 +14,9 @@
setup_threading_excepthook)
+UNICODE_GUARD_ENV = "PYTHONREGRTEST_UNICODE_GUARD"
+
+
def setup_tests(ns):
try:
stderr_fd = sys.__stderr__.fileno()
@@ -99,6 +102,13 @@ def _test_audit_hook(name, args):
from test.support.testresult import RegressionTestResult
RegressionTestResult.USE_XML = True
+ # 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}",
+ )
+
def replace_stdout():
"""Set stdout encoder error handler to backslashreplace (as stderr error