Skip to content

bpo-44647: Add a permanent Unicode-valued env var to regrtest #27187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/libregrtest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
setup_threading_excepthook)


UNICODE_GUARD_ENV = "PYTHONREGRTEST_UNICODE_GUARD"


def setup_tests(ns):
try:
stderr_fd = sys.__stderr__.fileno()
Expand Down Expand Up @@ -98,6 +101,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
Expand Down
10 changes: 9 additions & 1 deletion Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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')
Expand Down Expand Up @@ -1298,6 +1298,14 @@ def test_threading_excepthook(self):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.