Debug django tests
Question: I see that [TestCase](https://docs.python.org/3/library/unittest.html) has a
method
[Debug()](https://docs.python.org/3/library/unittest.html#unittest.TestCase.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?


Answer: ## 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
    

