updated test suite support

Robert Collins robertc at robertcollins.net
Fri Aug 26 00:11:42 BST 2005


Martin has merged about 80% of what I'm about to describe, and I'm
assured the final hunk will be merged today :)

(oh, and much of this is now in HACKING).

We're now using stock unittest infrastructure - the bzr test suite can
be correctly run by any of the test runners out there. There is a
bzrlib.test_suite() function that returns a test suite for bzrlib. This
should be updated if we have additional child packages of bzrlib to
concatenate their respective test_suite()s.

The 'runTest' method is deprecated, we should be using the 'test_foo'
convention. I.e. rather than:

class TestCommandBar(TestCase):

    def runTest(self):
        pass

class TestCommandFoo(TestCase):

    def runTest(self):
        pass

we should do

class TestCommands(TestCase):
    
    def test_bar(self):
        pass

    def test_foo(self):
        pass


The reason for this is several fold:
 * It allows us to get better reuse out of setUp and tearDown methods.
 * unittest converts the docstrings on such methods into descriptions
for use - we need less machinery.
 * its the standard convention for xUnit in all the
introspection-supporting languages.

IO redirection is now not done by the test suite. This means that you
can use pdb to help diagnose a problem:

class TestCommands(TestCase):
    
    def test_bar(self):
        import pdb;pdb.set_trace()
        some_call_going_wrong()

will drop you into the debugger.

If you want to run a command with IO redirection in a test,
self.run_bzr() will do that. self.apply_redirected() will run arbitrary
callables with IO redirection.
     
There are now two distinct base classes for writing test cases:
bzrlib.selftest.TestCase and bzrlib.selftest.FunctionalTestCase
The former is appropriate for any 'memory-only' test cases that you
write. It sets up a log and captures mutter() etc calls.
FunctionalTestCase's setup constructs a temporary directory for your
test to run in and chdirs you to it.

Oh, and be sure to use Parent.setUp(self) (and tearDown()) when you
overide setUp and tearDown(). super() should not be used as the top of
the hierarchy doesn't use it, and I'm told that super must be used all
the way through or it introduces pain.

Cheers,
Rob

-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050826/9d761408/attachment.pgp 


More information about the bazaar mailing list