[issue16662] load_tests not invoked in package/__init__.py

Robert Collins report at bugs.python.org
Mon Sep 8 21:32:23 CEST 2014


Robert Collins added the comment:

Thanks for landing this barry, there's a couple quirks with your improvements - loadTestsFromModule(mod, foo, bar) will raise a TypeError but not warn about foo the way loadTestsFromModule(mod, foo) will.

Secondly, the TypeError has an off-by-one error in its output:

loadTestsFromModule(mod, foo, bar) will claim 2 arguments were passed. Three were.


diff -r d0ff527c53da Lib/unittest/loader.py
--- a/Lib/unittest/loader.py	Mon Sep 08 14:21:37 2014 -0400
+++ b/Lib/unittest/loader.py	Tue Sep 09 07:32:05 2014 +1200
@@ -79,12 +79,12 @@
         # use_load_tests argument.  For backward compatibility, we still
         # accept the argument (which can also be the first position) but we
         # ignore it and issue a deprecation warning if it's present.
-        if len(args) == 1 or 'use_load_tests' in kws:
+        if len(args) or 'use_load_tests' in kws:
             warnings.warn('use_load_tests is deprecated and ignored',
                           DeprecationWarning)
             kws.pop('use_load_tests', None)
         if len(args) > 1:
-            raise TypeError('loadTestsFromModule() takes 1 positional argument but {} were given'.format(len(args)))
+            raise TypeError('loadTestsFromModule() takes 1 positional argument but {} were given'.format(len(args) + 1))
         if len(kws) != 0:
             # Since the keyword arguments are unsorted (see PEP 468), just
             # pick the alphabetically sorted first argument to complain about,
diff -r d0ff527c53da Lib/unittest/test/test_loader.py
--- a/Lib/unittest/test/test_loader.py	Mon Sep 08 14:21:37 2014 -0400
+++ b/Lib/unittest/test/test_loader.py	Tue Sep 09 07:32:05 2014 +1200
@@ -272,7 +272,7 @@
         # however use_load_tests (which sorts first) is ignored.
         self.assertEqual(
             str(cm.exception),
-            'loadTestsFromModule() takes 1 positional argument but 2 were given')
+            'loadTestsFromModule() takes 1 positional argument but 3 were given')
 
     @warningregistry
     def test_loadTestsFromModule__use_load_tests_other_bad_keyword(self):

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16662>
_______________________________________


More information about the Python-bugs-list mailing list