]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44647: Add a permanent Unicode-valued env var to regrtest (GH-27187) (#27191)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 16 Jul 2021 13:55:26 +0000 (06:55 -0700)
committerGitHub <noreply@github.com>
Fri, 16 Jul 2021 13:55:26 +0000 (15:55 +0200)
(cherry picked from commit 7915c96ffd7ddc5cb6d54015ee4c31255a416892)

Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Lib/test/libregrtest/setup.py
Lib/test/test_regrtest.py
Misc/NEWS.d/next/Tests/2021-07-16-14-02-33.bpo-44647.5LzqIy.rst [new file with mode: 0644]

index 83ce2f73f4e5a62529b1ffd640576ceb61a3d8b5..472c6ebec00cb2888e4b4ef0ccd6399b3cf67d53 100644 (file)
@@ -14,6 +14,9 @@ from test.libregrtest.utils import (setup_unraisable_hook,
                                     setup_threading_excepthook)
 
 
+UNICODE_GUARD_ENV = "PYTHONREGRTEST_UNICODE_GUARD"
+
+
 def setup_tests(ns):
     try:
         stderr_fd = sys.__stderr__.fileno()
@@ -99,6 +102,13 @@ def setup_tests(ns):
         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
index 054776ccf4808aa94079ebc503d1dd77f144becd..75fa6f2d3f4d565457ac27f600a297b6c11e4151 100644 (file)
@@ -19,7 +19,7 @@ import unittest
 from test import libregrtest
 from test import support
 from test.support import os_helper
-from test.libregrtest import utils
+from test.libregrtest import utils, setup
 
 
 Py_DEBUG = hasattr(sys, 'gettotalrefcount')
@@ -1298,6 +1298,14 @@ class ArgsTestCase(BaseTestCase):
         self.assertIn("Warning -- Uncaught thread exception", output)
         self.assertIn("Exception: bug in thread", output)
 
+    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}":
+            # 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")
+
     def test_cleanup(self):
         dirname = os.path.join(self.tmptestdir, "test_python_123")
         os.mkdir(dirname)
diff --git a/Misc/NEWS.d/next/Tests/2021-07-16-14-02-33.bpo-44647.5LzqIy.rst b/Misc/NEWS.d/next/Tests/2021-07-16-14-02-33.bpo-44647.5LzqIy.rst
new file mode 100644 (file)
index 0000000..e4b2be2
--- /dev/null
@@ -0,0 +1,4 @@
+Added a permanent Unicode-valued environment variable to regression tests to
+ensure they handle this use case in the future. If your test environment
+breaks because of that, report a bug to us, and temporarily set
+PYTHONREGRTEST_UNICODE_GUARD=0 in your test environment.