[Python-checkins] cpython: #11078: test___all__ now checks for duplicates in __all__. Initial patch by R.

ezio.melotti python-checkins at python.org
Wed May 1 13:58:25 CEST 2013


http://hg.python.org/cpython/rev/3f1bcfbed022
changeset:   83580:3f1bcfbed022
parent:      83577:4e186581fea7
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Wed May 01 14:58:09 2013 +0300
summary:
  #11078: test___all__ now checks for duplicates in __all__.  Initial patch by R. David Murray.

files:
  Lib/test/test___all__.py |  25 ++++++++++++++-----------
  Misc/NEWS                |   3 +++
  2 files changed, 17 insertions(+), 11 deletions(-)


diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -29,17 +29,20 @@
         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)):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -176,6 +176,9 @@
 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

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


More information about the Python-checkins mailing list