summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-03-29 23:03:16 (GMT)
committerGitHub <noreply@github.com>2021-03-29 23:03:16 (GMT)
commitba7f8638f93b5d999b25d8556ca19bdc2e12f359 (patch)
treecdb59e3f098d7503faef3ec7a2aeba3a32ff4d4a /Lib/test
parent20b2f2bfc2e72c6d9ed983d1f0aa7a141e9b3fc3 (diff)
downloadcpython-ba7f8638f93b5d999b25d8556ca19bdc2e12f359.zip
cpython-ba7f8638f93b5d999b25d8556ca19bdc2e12f359.tar.gz
cpython-ba7f8638f93b5d999b25d8556ca19bdc2e12f359.tar.bz2
bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075)
(cherry picked from commit 09b90a037d18f5d4acdf1b14082e57bda78e85d3) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_sys.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index af0e54b..140c65a 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1441,6 +1441,21 @@ class SizeofTest(unittest.TestCase):
self.assertIsNone(cur.firstiter)
self.assertIsNone(cur.finalizer)
+ def test_changing_sys_stderr_and_removing_reference(self):
+ # If the default displayhook doesn't take a strong reference
+ # to sys.stderr the following code can crash. See bpo-43660
+ # for more details.
+ code = textwrap.dedent('''
+ import sys
+ class MyStderr:
+ def write(self, s):
+ sys.stderr = None
+ sys.stderr = MyStderr()
+ 1/0
+ ''')
+ rc, out, err = assert_python_failure('-c', code)
+ self.assertEqual(out, b"")
+ self.assertEqual(err, b"")
if __name__ == "__main__":
unittest.main()