Skip to content

Commit 26e3e94

Browse files
committed
Fix tests when run with -Werror
1 parent c9b21ef commit 26e3e94

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Lib/test/test_warnings/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,18 @@ def custom_showwarning(message, category, filename, lineno,
518518
file=None, line=None):
519519
warns.append(message)
520520

521-
with support.swap_attr(self.module, 'showwarning', custom_showwarning):
522-
with self.module.catch_warnings(record=True) as recorded:
523-
self.module.warn("recorded")
524-
self.assertEqual(len(recorded), 1)
525-
self.assertEqual(str(recorded[0].message), 'recorded')
526-
self.assertIs(self.module.showwarning, custom_showwarning)
527-
528-
self.module.warn("custom")
521+
with self.module.catch_warnings():
522+
self.module.resetwarnings()
523+
524+
with support.swap_attr(self.module, 'showwarning',
525+
custom_showwarning):
526+
with self.module.catch_warnings(record=True) as recorded:
527+
self.module.warn("recorded")
528+
self.assertEqual(len(recorded), 1)
529+
self.assertEqual(str(recorded[0].message), 'recorded')
530+
self.assertIs(self.module.showwarning, custom_showwarning)
531+
532+
self.module.warn("custom")
529533

530534
self.assertEqual(len(warns), 1)
531535
self.assertEqual(str(warns[0]), "custom")

0 commit comments

Comments
 (0)