[Python-checkins] cpython (merge 3.5 -> default): Issue #27063: Some unittest loader tests were silently skipped.

serhiy.storchaka python-checkins at python.org
Fri May 20 16:30:12 EDT 2016


https://hg.python.org/cpython/rev/f4f615edb6b1
changeset:   101458:f4f615edb6b1
parent:      101456:03b32f854680
parent:      101457:e715ffd2d938
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Fri May 20 23:29:07 2016 +0300
summary:
  Issue #27063: Some unittest loader tests were silently skipped.

files:
  Lib/unittest/test/test_loader.py |  54 ++++++++++---------
  1 files changed, 28 insertions(+), 26 deletions(-)


diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py
--- a/Lib/unittest/test/test_loader.py
+++ b/Lib/unittest/test/test_loader.py
@@ -8,7 +8,7 @@
 # test isolation and reproducibility.
 def warningregistry(func):
     def wrapper(*args, **kws):
-        missing = object()
+        missing = []
         saved = getattr(warnings, '__warningregistry__', missing).copy()
         try:
             return func(*args, **kws)
@@ -20,6 +20,7 @@
                     pass
             else:
                 warnings.__warningregistry__ = saved
+    return wrapper
 
 
 class Test_TestLoader(unittest.TestCase):
@@ -197,9 +198,9 @@
         # ignored (and deprecated).
         load_tests_args = []
         with warnings.catch_warnings(record=False):
-            warnings.simplefilter('never')
+            warnings.simplefilter('ignore')
             suite = loader.loadTestsFromModule(m, use_load_tests=False)
-            self.assertEqual(load_tests_args, [loader, suite, None])
+        self.assertEqual(load_tests_args, [loader, suite, None])
 
     @warningregistry
     def test_loadTestsFromModule__use_load_tests_deprecated_positional(self):
@@ -221,10 +222,10 @@
         with warnings.catch_warnings(record=True) as w:
             warnings.simplefilter('always')
             suite = loader.loadTestsFromModule(m, False)
-            self.assertIsInstance(suite, unittest.TestSuite)
-            # load_tests was still called because use_load_tests is deprecated
-            # and ignored.
-            self.assertEqual(load_tests_args, [loader, suite, None])
+        self.assertIsInstance(suite, unittest.TestSuite)
+        # load_tests was still called because use_load_tests is deprecated
+        # and ignored.
+        self.assertEqual(load_tests_args, [loader, suite, None])
         # We got a warning.
         self.assertIs(w[-1].category, DeprecationWarning)
         self.assertEqual(str(w[-1].message),
@@ -249,14 +250,14 @@
         with warnings.catch_warnings(record=True) as w:
             warnings.simplefilter('always')
             suite = loader.loadTestsFromModule(m, use_load_tests=False)
-            self.assertIsInstance(suite, unittest.TestSuite)
-            # load_tests was still called because use_load_tests is deprecated
-            # and ignored.
-            self.assertEqual(load_tests_args, [loader, suite, None])
-            # We got a warning.
-            self.assertIs(w[-1].category, DeprecationWarning)
-            self.assertEqual(str(w[-1].message),
-                                 'use_load_tests is deprecated and ignored')
+        self.assertIsInstance(suite, unittest.TestSuite)
+        # load_tests was still called because use_load_tests is deprecated
+        # and ignored.
+        self.assertEqual(load_tests_args, [loader, suite, None])
+        # We got a warning.
+        self.assertIs(w[-1].category, DeprecationWarning)
+        self.assertEqual(str(w[-1].message),
+                             'use_load_tests is deprecated and ignored')
 
     @warningregistry
     def test_loadTestsFromModule__too_many_positional_args(self):
@@ -274,17 +275,18 @@
         m.load_tests = load_tests
         loader = unittest.TestLoader()
         with self.assertRaises(TypeError) as cm, \
-             warnings.catch_warning(record=True) as w:
+             warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter('always')
             loader.loadTestsFromModule(m, False, 'testme.*')
-            # We still got the deprecation warning.
-            self.assertIs(w[-1].category, DeprecationWarning)
-            self.assertEqual(str(w[-1].message),
-                                 'use_load_tests is deprecated and ignored')
-            # We also got a TypeError for too many positional arguments.
-            self.assertEqual(type(cm.exception), TypeError)
-            self.assertEqual(
-                str(cm.exception),
-                'loadTestsFromModule() takes 1 positional argument but 3 were given')
+        # We still got the deprecation warning.
+        self.assertIs(w[-1].category, DeprecationWarning)
+        self.assertEqual(str(w[-1].message),
+                                'use_load_tests is deprecated and ignored')
+        # We also got a TypeError for too many positional arguments.
+        self.assertEqual(type(cm.exception), TypeError)
+        self.assertEqual(
+            str(cm.exception),
+            'loadTestsFromModule() takes 1 positional argument but 3 were given')
 
     @warningregistry
     def test_loadTestsFromModule__use_load_tests_other_bad_keyword(self):
@@ -302,7 +304,7 @@
         m.load_tests = load_tests
         loader = unittest.TestLoader()
         with warnings.catch_warnings():
-            warnings.simplefilter('never')
+            warnings.simplefilter('ignore')
             with self.assertRaises(TypeError) as cm:
                 loader.loadTestsFromModule(
                     m, use_load_tests=False, very_bad=True, worse=False)

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


More information about the Python-checkins mailing list