@@ -547,24 +547,33 @@ def test_pynumber_tobase(self):
547547 self .assertRaises (TypeError , pynumber_tobase , '123' , 10 )
548548 self .assertRaises (SystemError , pynumber_tobase , 123 , 0 )
549549
550- def test_fatal_error (self ):
551- code = 'import _testcapi; _testcapi.fatal_error(b"MESSAGE")'
550+ def check_fatal_error (self , code , expected , not_expected = ()):
552551 with support .SuppressCrashReport ():
553552 rc , out , err = assert_python_failure ('-sSI' , '-c' , code )
554553
555554 err = err .replace (b'\r ' , b'' ).decode ('ascii' , 'replace' )
556555 self .assertIn ('Fatal Python error: test_fatal_error: MESSAGE\n ' ,
557556 err )
558557
559- match = re .search ('^Extension modules:(.*)$' , err , re .MULTILINE )
558+ match = re .search (r'^Extension modules:(.*) \(total: ([0-9]+)\)$' ,
559+ err , re .MULTILINE )
560560 if not match :
561561 self .fail (f"Cannot find 'Extension modules:' in { err !r} " )
562562 modules = set (match .group (1 ).strip ().split (', ' ))
563- # Test _PyModule_IsExtension(): the list doesn't have to
564- # be exhaustive.
565- for name in ('sys' , 'builtins' , '_imp' , '_thread' , '_weakref' ,
566- '_io' , 'marshal' , '_signal' , '_abc' , '_testcapi' ):
563+ total = int (match .group (2 ))
564+
565+ for name in expected :
567566 self .assertIn (name , modules )
567+ for name in not_expected :
568+ self .assertNotIn (name , modules )
569+ self .assertEqual (len (modules ), total )
570+
571+ def test_fatal_error (self ):
572+ expected = ('_testcapi' ,)
573+ not_expected = ('sys' , 'builtins' , '_imp' , '_thread' , '_weakref' ,
574+ '_io' , 'marshal' , '_signal' , '_abc' )
575+ code = 'import _testcapi; _testcapi.fatal_error(b"MESSAGE")'
576+ self .check_fatal_error (code , expected , not_expected )
568577
569578
570579class TestPendingCalls (unittest .TestCase ):
0 commit comments