@@ -1110,7 +1110,7 @@ def assertNotWarn(self, callable, msg=''):
11101110 r"""
11111111 Test if :attr:`callable` does not raise a warning.
11121112 """
1113- with self . _reset_warning_registry (), warnings .catch_warnings (record = True ) as ws :
1113+ with warnings .catch_warnings (record = True ) as ws :
11141114 warnings .simplefilter ("always" ) # allow any warning to be raised
11151115 callable ()
11161116 self .assertTrue (len (ws ) == 0 , msg )
@@ -1122,7 +1122,7 @@ def maybeWarnsRegex(self, category, regex=''):
11221122 This filters expected warnings from the test log and fails the test if
11231123 any unexpected warnings are caught.
11241124 """
1125- with self . _reset_warning_registry (), warnings .catch_warnings (record = True ) as ws :
1125+ with warnings .catch_warnings (record = True ) as ws :
11261126 warnings .simplefilter ("always" ) # allow any warning to be raised
11271127 # Ignore expected warnings
11281128 warnings .filterwarnings ("ignore" , message = regex , category = category )
@@ -1137,46 +1137,6 @@ def maybeWarnsRegex(self, category, regex=''):
11371137 msg += '\n '
11381138 self .fail (msg )
11391139
1140- @contextmanager
1141- def _reset_warning_registry (self ):
1142- r"""
1143- warnings.catch_warnings() in Python 2 misses already registered
1144- warnings. We need to manually clear the existing warning registries to
1145- ensure catching warnings in a scope.
1146- """
1147- # Python 3 has no problem.
1148- if sys .version_info >= (3 ,):
1149- yield
1150- return
1151-
1152- # Backup and clear all existing warning registries.
1153- backup = {}
1154- for name , mod in list (sys .modules .items ()):
1155- try :
1156- reg = mod .__warningregistry__
1157- except AttributeError :
1158- continue
1159- else :
1160- backup [name ] = reg .copy ()
1161- reg .clear ()
1162-
1163- yield
1164-
1165- # Restore backed up warning registries.
1166- for name , reg_orig in backup .items ():
1167- try :
1168- mod = sys .modules [name ]
1169- except KeyError :
1170- continue
1171-
1172- try :
1173- reg = mod .__warningregistry__
1174- except AttributeError :
1175- mod .__warningregistry__ = reg_orig
1176- else :
1177- reg .clear ()
1178- reg .update (reg_orig )
1179-
11801140 def assertExpected (self , s , subname = None ):
11811141 r"""
11821142 Test that a string matches the recorded contents of a file
0 commit comments