[Bug 726257] Re: unittest does not detect TestSuite's properly

dino99 726257 at bugs.launchpad.net
Sun May 3 13:32:24 UTC 2015


Support for this version has ended

** Changed in: python2.6 (Ubuntu)
       Status: New => Invalid

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

Title:
  unittest does not detect TestSuite's properly

Status in python2.6 package in Ubuntu:
  Invalid

Bug description:
  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

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python2.6/+bug/726257/+subscriptions



More information about the foundations-bugs mailing list