@@ -1223,7 +1223,7 @@ def test_regex(self):
1223
1223
lambda : assert_string_equal ("aaa" , "a+b" ))
1224
1224
1225
1225
1226
- def assert_warn_len_equal (mod , n_in_context , py37 = None ):
1226
+ def assert_warn_len_equal (mod , n_in_context ):
1227
1227
try :
1228
1228
mod_warns = mod .__warningregistry__
1229
1229
except AttributeError :
@@ -1243,15 +1243,9 @@ def assert_warn_len_equal(mod, n_in_context, py37=None):
1243
1243
# do not count it.
1244
1244
num_warns -= 1
1245
1245
1246
- # Behavior of warnings is Python version dependent. Adjust the
1247
- # expected result to compensate. In particular, Python 3.7 does
1248
- # not make an entry for ignored warnings.
1249
- if sys .version_info [:2 ] >= (3 , 7 ):
1250
- if py37 is not None :
1251
- n_in_context = py37
1252
-
1253
1246
assert_equal (num_warns , n_in_context )
1254
1247
1248
+
1255
1249
def test_warn_len_equal_call_scenarios ():
1256
1250
# assert_warn_len_equal is called under
1257
1251
# varying circumstances depending on serial
@@ -1300,23 +1294,28 @@ def test_clear_and_catch_warnings():
1300
1294
warnings .simplefilter ('ignore' )
1301
1295
warnings .warn ('Some warning' )
1302
1296
assert_equal (my_mod .__warningregistry__ , {})
1303
- # Without specified modules, don't clear warnings during context
1304
- # Python 3.7 catch_warnings doesn't make an entry for 'ignore'.
1297
+ # Without specified modules, don't clear warnings during context.
1298
+ # catch_warnings doesn't make an entry for 'ignore'.
1305
1299
with clear_and_catch_warnings ():
1306
1300
warnings .simplefilter ('ignore' )
1307
1301
warnings .warn ('Some warning' )
1308
- assert_warn_len_equal (my_mod , 1 , py37 = 0 )
1302
+ assert_warn_len_equal (my_mod , 0 )
1303
+
1304
+ # Manually adding two warnings to the registry:
1305
+ my_mod .__warningregistry__ = {'warning1' : 1 ,
1306
+ 'warning2' : 2 }
1307
+
1309
1308
# Confirm that specifying module keeps old warning, does not add new
1310
1309
with clear_and_catch_warnings (modules = [my_mod ]):
1311
1310
warnings .simplefilter ('ignore' )
1312
1311
warnings .warn ('Another warning' )
1313
- assert_warn_len_equal (my_mod , 1 , py37 = 0 )
1314
- # Another warning, no module spec does add to warnings dict, except on
1315
- # Python 3.7 catch_warnings doesn't make an entry for 'ignore'.
1312
+ assert_warn_len_equal (my_mod , 2 )
1313
+
1314
+ # Another warning, no module spec it clears up registry
1316
1315
with clear_and_catch_warnings ():
1317
1316
warnings .simplefilter ('ignore' )
1318
1317
warnings .warn ('Another warning' )
1319
- assert_warn_len_equal (my_mod , 2 , py37 = 0 )
1318
+ assert_warn_len_equal (my_mod , 0 )
1320
1319
1321
1320
1322
1321
def test_suppress_warnings_module ():
@@ -1345,7 +1344,7 @@ def warn(arr):
1345
1344
# got filtered)
1346
1345
assert_equal (len (sup .log ), 1 )
1347
1346
assert_equal (sup .log [0 ].message .args [0 ], "Some warning" )
1348
- assert_warn_len_equal (my_mod , 0 , py37 = 0 )
1347
+ assert_warn_len_equal (my_mod , 0 )
1349
1348
sup = suppress_warnings ()
1350
1349
# Will have to be changed if apply_along_axis is moved:
1351
1350
sup .filter (module = my_mod )
@@ -1358,12 +1357,12 @@ def warn(arr):
1358
1357
warnings .warn ('Some warning' )
1359
1358
assert_warn_len_equal (my_mod , 0 )
1360
1359
1361
- # Without specified modules, don't clear warnings during context
1362
- # Python 3.7 does not add ignored warnings.
1360
+ # Without specified modules
1363
1361
with suppress_warnings ():
1364
1362
warnings .simplefilter ('ignore' )
1365
1363
warnings .warn ('Some warning' )
1366
- assert_warn_len_equal (my_mod , 1 , py37 = 0 )
1364
+ assert_warn_len_equal (my_mod , 0 )
1365
+
1367
1366
1368
1367
def test_suppress_warnings_type ():
1369
1368
# Initial state of module, no warnings
@@ -1386,12 +1385,11 @@ def test_suppress_warnings_type():
1386
1385
warnings .warn ('Some warning' )
1387
1386
assert_warn_len_equal (my_mod , 0 )
1388
1387
1389
- # Without specified modules, don't clear warnings during context
1390
- # Python 3.7 does not add ignored warnings.
1388
+ # Without specified modules
1391
1389
with suppress_warnings ():
1392
1390
warnings .simplefilter ('ignore' )
1393
1391
warnings .warn ('Some warning' )
1394
- assert_warn_len_equal (my_mod , 1 , py37 = 0 )
1392
+ assert_warn_len_equal (my_mod , 0 )
1395
1393
1396
1394
1397
1395
def test_suppress_warnings_decorate_no_record ():
0 commit comments