unittest / pdb tricks? 
Author Message
 unittest / pdb tricks?

I'm doing a lot of work with the unittest module right now.  I like
the default behavior of unittest.main(), where it runs as many tests
as it can, even if some fail.

But, what I also want is the option to be able to do "pdb.pm()" when a
test fails.  Looking at the source for unittest.py, it doesn't look
like there's a way to have the failure "fail far enough" to run

Do other people do this?  If so, what's an easy and clean way to do


- Sam

Sun, 15 Feb 2004 04:24:57 GMT  
 unittest / pdb tricks?

Hi, Sam.  Below is the subclass of TestCase that I use to make unittests
throw an exception and drop back into the interpreter when they fail.
You can turn this behaviour off on a case-by-case basis by overriding
the value of __stopOnError__.  I find it useful to do that for some
tests whose failures don't indicate such urgent problems, like the CVS
repository not being completely up-to-date.


class TestCase(unittest.TestCase):

    """Version of TestCase that can be easily run independantly of the
    testing framework."""

    __stopOnError__ = 1

    def __init__(self, *args, **kw):

        if args: apply(unittest.TestCase.__init__, (self,) + args, kw)

    def throwsException(self, test_function, expected_exc):

        """True if  'test_function()' throws 'expected_exc'"""

        try: test_function()
        except expected_exc: return 1

    def __call__(self, result=None):

        if self.__stopOnError__:
            self.setUp(); self.__testMethod(); self.tearDown();
            unittest.TestCase.__call__(self, result)

Sun, 15 Feb 2004 05:56:17 GMT  
 [ 2 post ] 

 Relevant Pages 

1. pdb.el - using pdb from xemacs

2. unittest: how to specify which suites to run with unittest.main()?

3. Need help Translating Python unittest to Ruby Test::Unit

4. The various UnitTest frameworks.

5. Windows python 2.2.1 IDLE glitch - unittest output display nothing

6. problems redirecting unittest output to sys.stdout

7. print unittest errors immediately

8. Code Coverage support for unittest?

9. Tkinter and unittest

10. A modest suggestion for unittest.py

11. Standard module unittest, where has unittestgui gone?

12. Notes on unittest.py


Powered by phpBB® Forum Software