@@ -1235,10 +1235,12 @@ def test_sleep(self):
1235
1235
re .compile ('%s timed out' % testname , re .MULTILINE ))
1236
1236
1237
1237
def test_unraisable_exc (self ):
1238
- # --fail-env-changed must catch unraisable exception
1238
+ # --fail-env-changed must catch unraisable exception.
1239
+ # The exceptioin must be displayed even if sys.stderr is redirected.
1239
1240
code = textwrap .dedent (r"""
1240
1241
import unittest
1241
1242
import weakref
1243
+ from test.support import captured_stderr
1242
1244
1243
1245
class MyObject:
1244
1246
pass
@@ -1250,9 +1252,11 @@ class Tests(unittest.TestCase):
1250
1252
def test_unraisable_exc(self):
1251
1253
obj = MyObject()
1252
1254
ref = weakref.ref(obj, weakref_callback)
1253
- # call weakref_callback() which logs
1254
- # an unraisable exception
1255
- obj = None
1255
+ with captured_stderr() as stderr:
1256
+ # call weakref_callback() which logs
1257
+ # an unraisable exception
1258
+ obj = None
1259
+ self.assertEqual(stderr.getvalue(), '')
1256
1260
""" )
1257
1261
testname = self .create_test (code = code )
1258
1262
@@ -1261,6 +1265,7 @@ def test_unraisable_exc(self):
1261
1265
env_changed = [testname ],
1262
1266
fail_env_changed = True )
1263
1267
self .assertIn ("Warning -- Unraisable exception" , output )
1268
+ self .assertIn ("Exception: weakref callback bug" , output )
1264
1269
1265
1270
def test_cleanup (self ):
1266
1271
dirname = os .path .join (self .tmptestdir , "test_python_123" )
0 commit comments