0

I see that TestCase has a method Debug(), but I can't find any example on how to implement it. As far as I've tried, nothing works.

Can anyone provide some code as to how to use it?

Ben
  • 6,986
  • 6
  • 44
  • 71

1 Answers1

0

debugunit.py

from unittest import TestCase

class MyTest(TestCase):
    def test1(self):
        print 'before'
        self.assertEquals(2+2, 5)
        print 'after'

run

python -i debugunit.py

To run a test interactively, create a TestCase instance, giving it the test name as a parameter. To run it, call the resulting object.

>>> print MyTest('test1')()
before
None

The "2+2!=5" exception is consumed by the unittest machinery. To get the set to run (with setUp and tearDown, etc), run the debug() method:

>>> MyTest('test1').debug()
before
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/unittest/case.py", line 400, in debug
    getattr(self, self._testMethodName)()
  File "debugunit.py", line 6, in test1
    self.assertEquals(2+2, 5)
  File "/usr/lib/python2.7/unittest/case.py", line 515, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python2.7/unittest/case.py", line 508, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 4 != 5
johntellsall
  • 14,394
  • 4
  • 46
  • 40
  • For sure, I've been using `pdb`. I was just curious if `TestCase.Debug()` offered something better. Can you explain how to fire up the test manually? – Ben Jun 05 '14 at 05:05
  • @ben I replaced the answer with how to use `debug()` -- hope this helps! – johntellsall Jun 05 '14 at 18:21