From a35169907512d720c58f713812aab009f5749a18 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 25 Apr 2022 11:16:42 +0300 Subject: [PATCH 1/2] gh-91904: Fix setting envvar PYTHONREGRTEST_UNICODE_GUARD It always failed on non-UTF-8 locale and prevented running regrtests. --- Lib/test/libregrtest/setup.py | 9 +++++---- Lib/test/test_regrtest.py | 2 +- .../Tests/2022-04-25-11-16-36.gh-issue-91904.13Uvrz.rst | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2022-04-25-11-16-36.gh-issue-91904.13Uvrz.rst diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py index 4ffd15478f6437..be68331ca5206f 100644 --- a/Lib/test/libregrtest/setup.py +++ b/Lib/test/libregrtest/setup.py @@ -5,6 +5,7 @@ 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 _test_audit_hook(name, args): # 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 hasattr(os, 'environb'): + os.environb.setdefault(UNICODE_GUARD_ENV.encode(), TESTFN_UNDECODABLE) + elif FS_NONASCII: + os.environ.setdefault(UNICODE_GUARD_ENV, FS_NONASCII) def replace_stdout(): diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index babc8a690877a2..15e2f89ee20c1d 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -1339,7 +1339,7 @@ def test_print_warning(self): 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 index 00000000000000..c06390993e04f5 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-04-25-11-16-36.gh-issue-91904.13Uvrz.rst @@ -0,0 +1,2 @@ +Fix initialization of :env:`PYTHONREGRTEST_UNICODE_GUARD` which prevented +running regression tests on non-UTF-8 locale. From f16859b34832eab195cb0f0e563c584c577aae91 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 25 Apr 2022 11:45:59 +0300 Subject: [PATCH 2/2] Fix markup. --- Lib/test/libregrtest/setup.py | 2 +- .../next/Tests/2022-04-25-11-16-36.gh-issue-91904.13Uvrz.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py index be68331ca5206f..cfc1b82d2785cb 100644 --- a/Lib/test/libregrtest/setup.py +++ b/Lib/test/libregrtest/setup.py @@ -105,7 +105,7 @@ def _test_audit_hook(name, args): # Ensure there's a non-ASCII character in env vars at all times to force # tests consider this case. See BPO-44647 for details. - if TESTFN_UNDECODABLE and hasattr(os, 'environb'): + 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) 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 index c06390993e04f5..31ddfc312866b8 100644 --- 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 @@ -1,2 +1,2 @@ -Fix initialization of :env:`PYTHONREGRTEST_UNICODE_GUARD` which prevented +Fix initialization of :envvar:`PYTHONREGRTEST_UNICODE_GUARD` which prevented running regression tests on non-UTF-8 locale.