]> granicus.if.org Git - python/commitdiff
#11078: test___all__ now checks for duplicates in __all__. Initial patch by R. David...
authorEzio Melotti <ezio.melotti@gmail.com>
Wed, 1 May 2013 11:58:09 +0000 (14:58 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Wed, 1 May 2013 11:58:09 +0000 (14:58 +0300)
Lib/test/test___all__.py
Misc/NEWS

index 608ec01f14017b60c79db608066bb2771313c3e5..093ea2f99ec6e257507c41d5ad2ed34a0891899a 100644 (file)
@@ -29,17 +29,20 @@ class AllTest(unittest.TestCase):
         if not hasattr(sys.modules[modname], "__all__"):
             raise NoAll(modname)
         names = {}
-        try:
-            exec("from %s import *" % modname, names)
-        except Exception as e:
-            # Include the module name in the exception string
-            self.fail("__all__ failure in {}: {}: {}".format(
-                      modname, e.__class__.__name__, e))
-        if "__builtins__" in names:
-            del names["__builtins__"]
-        keys = set(names)
-        all = set(sys.modules[modname].__all__)
-        self.assertEqual(keys, all)
+        with self.subTest(module=modname):
+            try:
+                exec("from %s import *" % modname, names)
+            except Exception as e:
+                # Include the module name in the exception string
+                self.fail("__all__ failure in {}: {}: {}".format(
+                          modname, e.__class__.__name__, e))
+            if "__builtins__" in names:
+                del names["__builtins__"]
+            keys = set(names)
+            all_list = sys.modules[modname].__all__
+            all_set = set(all_list)
+            self.assertCountEqual(all_set, all_list, "in module {}".format(modname))
+            self.assertEqual(keys, all_set, "in module {}".format(modname))
 
     def walk_modules(self, basedir, modpath):
         for fn in sorted(os.listdir(basedir)):
index f50d23a1f7b98ca97bb92e2f5becf84f1e3d452c..ee4c73a900ecd6cbc4534c0fc8de3dcab4631b54 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -176,6 +176,9 @@ Library
 Tests
 -----
 
+- Issue #11078: test___all__ now checks for duplicates in __all__.
+  Initial patch by R. David Murray.
+
 - Issue #17712: Fix test_gdb failures on Ubuntu 13.04.
 
 - Issue #17835: Fix test_io when the default OS pipe buffer size is larger