summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-02-12 17:27:55 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-02-12 17:27:55 (GMT)
commit8da4fb5a1c99e7d05c6417def3ef145790f2fa41 (patch)
treea81d40ef543c5b9b1772fec8eb17f14d9fca00f9
parent76a63260685b0778e85f55f60b3bf82c66075e99 (diff)
downloadcpython-8da4fb5a1c99e7d05c6417def3ef145790f2fa41.zip
cpython-8da4fb5a1c99e7d05c6417def3ef145790f2fa41.tar.gz
cpython-8da4fb5a1c99e7d05c6417def3ef145790f2fa41.tar.bz2
Issue #20599: Force ASCII encoding for stdout in test_cleanup() of test_builtin
On Windows, the codec of sys.stdout is implemented in Python. At exit, the codec may be unloaded before the destructor tries to write something to sys.stdout.
-rw-r--r--Lib/test/test_builtin.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 8a307b9..5c14de3 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1604,10 +1604,10 @@ class ShutdownTest(unittest.TestCase):
class C:
def __del__(self):
- print("before", flush=True)
+ print("before")
# Check that builtins still exist
len(())
- print("after", flush=True)
+ print("after")
c = C()
# Make this module survive until builtins and sys are cleaned
@@ -1617,7 +1617,15 @@ class ShutdownTest(unittest.TestCase):
# through a GC phase.
here = sys.modules[__name__]
"""
- rc, out, err = assert_python_ok("-c", code)
+ # Issue #20599: Force ASCII encoding to get a codec implemented in C,
+ # otherwise the codec may be unloaded before C.__del__() is called, and
+ # so print("before") fails because the codec cannot be used to encode
+ # "before" to sys.stdout.encoding. For example, on Windows,
+ # sys.stdout.encoding is the OEM code page and these code pages are
+ # implemented in Python
+ rc, out, err = assert_python_ok("-c", code,
+ PYTHONIOENCODING="ascii",
+ __cleanenv=True)
self.assertEqual(["before", "after"], out.decode().splitlines())