diff options
author | Brett Cannon <brett@python.org> | 2011-07-18 02:17:55 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2011-07-18 02:17:55 (GMT) |
commit | 52a7d982736fd4111b7937c4e575adb1a39f8afa (patch) | |
tree | 81a73e3f745620057a1f0486b9fa08fddac0dd47 /Lib/test/test_warnings.py | |
parent | b05be7d936051a04a529fb7ad63731aeabe0fb9b (diff) | |
download | cpython-52a7d982736fd4111b7937c4e575adb1a39f8afa.zip cpython-52a7d982736fd4111b7937c4e575adb1a39f8afa.tar.gz cpython-52a7d982736fd4111b7937c4e575adb1a39f8afa.tar.bz2 |
Make warnings accept a callable for showwarnings instead of
restricting itself to just functions and methods (which allows
built-in functions to be used, etc.).
Closes issue #10271. Thanks to lekma for the bug report.
Diffstat (limited to 'Lib/test/test_warnings.py')
-rw-r--r-- | Lib/test/test_warnings.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index 79be835..953b282 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -512,12 +512,11 @@ class _WarningsTests(BaseTest): def test_showwarning_not_callable(self): with original_warnings.catch_warnings(module=self.module): self.module.filterwarnings("always", category=UserWarning) - old_showwarning = self.module.showwarning + self.module.showwarning = print + with support.captured_output('stdout'): + self.module.warn('Warning!') self.module.showwarning = 23 - try: - self.assertRaises(TypeError, self.module.warn, "Warning!") - finally: - self.module.showwarning = old_showwarning + self.assertRaises(TypeError, self.module.warn, "Warning!") def test_show_warning_output(self): # With showarning() missing, make sure that output is okay. @@ -547,10 +546,13 @@ class _WarningsTests(BaseTest): globals_dict = globals() oldfile = globals_dict['__file__'] try: - with original_warnings.catch_warnings(module=self.module) as w: + catch = original_warnings.catch_warnings(record=True, + module=self.module) + with catch as w: self.module.filterwarnings("always", category=UserWarning) globals_dict['__file__'] = None original_warnings.warn('test', UserWarning) + self.assertTrue(len(w)) finally: globals_dict['__file__'] = oldfile |