]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91904: Fix setting envvar PYTHONREGRTEST_UNICODE_GUARD (GH-91905)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 25 Apr 2022 14:35:14 +0000 (17:35 +0300)
committerGitHub <noreply@github.com>
Mon, 25 Apr 2022 14:35:14 +0000 (17:35 +0300)
It always failed on non-UTF-8 locale and prevented running regrtests.

Lib/test/libregrtest/setup.py
Lib/test/test_regrtest.py
Misc/NEWS.d/next/Tests/2022-04-25-11-16-36.gh-issue-91904.13Uvrz.rst [new file with mode: 0644]

index 4ffd15478f6437d073c28888e28d4d4bc8a4a7ca..cfc1b82d2785cbbddbcd773191c0fdce23d07a04 100644 (file)
@@ -5,6 +5,7 @@ import signal
 import sys
 import unittest
 from test import support
+from test.support.os_helper import TESTFN_UNDECODABLE, FS_NONASCII
 try:
     import gc
 except ImportError:
@@ -104,10 +105,10 @@ def setup_tests(ns):
 
     # 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():
index babc8a690877a2b0b3c554704a143330c7476ad2..15e2f89ee20c1d4f76792b5448eecda332be6db8 100644 (file)
@@ -1339,7 +1339,7 @@ class ArgsTestCase(BaseTestCase):
     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")
diff --git a/Misc/NEWS.d/next/Tests/2022-04-25-11-16-36.gh-issue-91904.13Uvrz.rst b/Misc/NEWS.d/next/Tests/2022-04-25-11-16-36.gh-issue-91904.13Uvrz.rst
new file mode 100644 (file)
index 0000000..31ddfc3
--- /dev/null
@@ -0,0 +1,2 @@
+Fix initialization of :envvar:`PYTHONREGRTEST_UNICODE_GUARD` which prevented
+running regression tests on non-UTF-8 locale.