Author rbcollins
Recipients barry, chris.jerdonek, elopio, michael.foord, python-dev, r.david.murray, rbcollins, vila, zach.ware
Date 2014-09-08.19:32:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1410204743.11.0.646927316891.issue16662@psf.upfronthosting.co.za>
In-reply-to
Content
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):
History
Date User Action Args
2014-09-08 19:32:23rbcollinssetrecipients: + rbcollins, barry, vila, r.david.murray, michael.foord, chris.jerdonek, python-dev, zach.ware, elopio
2014-09-08 19:32:23rbcollinssetmessageid: <1410204743.11.0.646927316891.issue16662@psf.upfronthosting.co.za>
2014-09-08 19:32:23rbcollinslinkissue16662 messages
2014-09-08 19:32:22rbcollinscreate