[Python-checkins] cpython (2.7): Issue #23029: Fix catch_warnings() in test_filename_none

berker.peksag python-checkins at python.org
Sat Apr 16 15:14:53 EDT 2016


https://hg.python.org/cpython/rev/009e36e6d16d
changeset:   101018:009e36e6d16d
branch:      2.7
parent:      101012:e3ed950ad728
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Sat Apr 16 22:16:05 2016 +0300
summary:
  Issue #23029: Fix catch_warnings() in test_filename_none

It was printed UserWarning output because catch_warnings() was missing
record=True.

files:
  Lib/test/test_warnings.py |  5 ++++-
  1 files changed, 4 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -553,10 +553,13 @@
         globals_dict = globals()
         oldfile = globals_dict['__file__']
         try:
-            with original_warnings.catch_warnings(module=self.module) as w:
+            with original_warnings.catch_warnings(module=self.module, record=True) as w:
                 self.module.filterwarnings("always", category=UserWarning)
                 globals_dict['__file__'] = None
                 self.module.warn('test', UserWarning)
+            self.assertEqual(len(w), 1)
+            self.assertEqual(w[0].category, UserWarning)
+            self.assertEqual(str(w[0].message), 'test')
         finally:
             globals_dict['__file__'] = oldfile
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list