Public bug reported:

Binary package hint: python2.6

The following condition, on line 595 of unittest.py does not function
correctly:

        elif isinstance(obj, TestSuite):

For whatever reason, when "obj" is in fact an instnance of a TestSuite
object, it is not detected as such. Worth noting - I have tested this
with the Ubuntu supplied python2.7 and the problem goes away. Here is a
simple test case:

#mytest.py
import unittest

class BasicTests(unittest.TestCase):
    def runTest(self):
        self.assertTrue(True)

suite = unittest.TestSuite()
suite.addTests([BasicTests()])


Run the above code from the command line:
> python -m unittest mytest.suite

You get an error like the following:

Traceback (most recent call last):
  File "/usr/lib/python2.6/runpy.py", line 122, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.6/unittest.py", line 875, in <module>
    main(module=None)
  File "/usr/lib/python2.6/unittest.py", line 816, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python2.6/unittest.py", line 843, in parseArgs
    self.createTests()
  File "/usr/lib/python2.6/unittest.py", line 849, in createTests
    self.module)
  File "/usr/lib/python2.6/unittest.py", line 613, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.6/unittest.py", line 598, in loadTestsFromName
    test = obj()
  File "/usr/lib/python2.6/unittest.py", line 464, in __call__
    return self.run(*args, **kwds)
TypeError: run() takes exactly 2 arguments (1 given)

This is happening because the condition is failing, so execution is
falling through to the final "else" block, where it tries to execute the
TestSuite as a function:

        elif isinstance(obj, TestSuite):
            return obj
        elif hasattr(obj, '__call__'):
            test = obj() #EXCEPTION RAISED HERE

** Affects: python2.6 (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/726257

Title:
  unittest does not detect TestSuite's properly

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to