This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Handle: class MyTest(unittest.TestSuite)
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: purcell Nosy List: georg.brandl, irmen, jjlee, jlgijsbers, purcell, rhettinger
Priority: high Keywords:

Created on 2004-01-16 14:22 by rhettinger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg19709 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-01-16 14:22
TestCases are supposed to be derived from 
unittest.TestCase; however, if they are derived from 
unittest.TestSuite, the traceback is inexplicable and 
hard to diagnose:


Traceback (most recent call last):
  File "C:/pydev/tmp.py", line 10, in -toplevel-
    unittest.TextTestRunner(verbosity=2).run(suite)
  File "C:\PY24\lib\unittest.py", line 690, in run
    test(result)
  File "C:\PY24\lib\unittest.py", line 423, in __call__
    test(result)
  File "C:\PY24\lib\unittest.py", line 423, in __call__
    test(result)
  File "C:\PY24\lib\unittest.py", line 423, in __call__
    test(result)
TypeError: 'str' object is not callable

Let's either improve the error message or make it 
possible to derive from TestSuite.

The above traceback is produced by the following script:

import unittest

class TestStats(unittest.TestSuite):

    def testtwo(self):
        self.assertEqual(2,2)

suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestStats))
unittest.TextTestRunner(verbosity=2).run(suite)
msg19710 - (view) Author: Irmen de Jong (irmen) (Python triager) Date: 2004-11-07 13:39
Logged In: YES 
user_id=129426

patch is at #1061904
msg19711 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-11-07 15:53
Logged In: YES 
user_id=469548

Well, the error message above has been fixed, but here's
another equally confusing variant:

import unittest

class TestStats(unittest.TestSuite):
    def testtwo(self):
        self.assertEqual(2,2)

suite = unittest.TestSuite([TestStats])
unittest.TextTestRunner(verbosity=2).run(suite)

giving:

Traceback (most recent call last):
  File "test-foo.py", line 8, in ?
    unittest.TextTestRunner(verbosity=2).run(suite)
  File "/home/johannes/python/Lib/unittest.py", line 695, in run
    test(result)
  File "/home/johannes/python/Lib/unittest.py", line 426, in
__call__
    test(result)
  File "/home/johannes/python/Lib/unittest.py", line 396, in
__init__
    self.addTests(tests)
  File "/home/johannes/python/Lib/unittest.py", line 416, in
addTests
    for test in tests:
TypeError: iteration over non-sequence

so I'm leaving this open.
msg19712 - (view) Author: John J Lee (jjlee) Date: 2005-12-04 18:52
Logged In: YES 
user_id=261020

Just to be clear: The issue with jlgijsbers' odd error
message (in his 2004-11-07 followup) is not that a TestSuite
is passed to the TestSuite constructor, but rather that he's
passing in a class, not an instance.

The error would show up a bit earlier if a check were added
to TestSuite.addTest():

if type(test) == type: raise TypeError('addTest argument 1
must be instance, not class')

I will post that line as a patch if anyone emails me to
request it!
msg19713 - (view) Author: John J Lee (jjlee) Date: 2005-12-04 19:24
Logged In: YES 
user_id=261020

In fact in jlgijsbers' case (TestSuite class passed to
TestSuite, rather than another bug: TestCase class passed to
TestSuite), that check just pushes the problem back a bit:

import unittest
class TestStats(unittest.TestSuite):
    def testtwo(self):
        self.assertEqual(2,2)
suite = unittest.TestSuite([TestStats('testtwo')])
unittest.TextTestRunner(verbosity=2).run(suite)

TypeError: 'str' object is not callable

Another test could be added to TestSuite addTest():

if not callable(test): raise TypeError('addTest argument 1
must be callable')

Again, though it does makes the error clearer, it seems
debatable that it's worth the change...
msg19714 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-07 11:55
Added a few sanity checks in rev. 54207, 54208 (2.5).
History
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39827
2004-01-16 14:22:28rhettingercreate