How do you debug when a unittest.TestCase fails?

Emin.shopper Martinian.shopper emin.shopper at gmail.com
Wed Jul 18 16:40:46 EDT 2007


Dear Experts,

How do you use pdb to debug when a TestCase object from the unittest module
fails? Basically, I'd like to run my unit tests and invoke pdb.pm when
something fails.

I tried the following with now success:

Imagine that I have a module _test.py that looks like the following:

-----------------------
import unittest
class MyTest(unittest.TestCase):
    def testIt(self):
        raise Exception('boom')
if __name__ == '__main__':
    unittest.main()
-----------------------

If I do

>>> import _test; _test.unittest()

no tests get run.

If I try

>>> import _test; t = _test.MyTest()

I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\unittest.py", line 209, in __init__
    (self.__class__, methodName)
ValueError: no such test method in <class '_test.MyTest'>: runTest

If I try

>>> import _test; t = _test.MyTest(methodName='testIt'); t.run()

nothing happens.

Thanks,
-Emin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070718/201648ff/attachment.html>


More information about the Python-list mailing list