how to make all assertions in a unit test execute

jimgardener jimgardener at gmail.com
Sat Oct 16 04:00:30 EDT 2010


hi
I was testing a function using unittest.

def get_filenames(dirname,innerstring):
    ....
    return filenames_containing_innerstring


class FileNamesTest(unittest.TestCase):
     def setUp(self):
        self.dirname='/home/me/data'

    def test_get_filenames(self):
        innerstr='tom'
        matching_names=get_filenames(self.dirname,innerstr)
        self.assertEquals(1,len(matching_names))

        innerstr='myself'
        matching_names=get_filenames(self.dirname,innerstr)
        self.assertEquals(0,len(matching_names))

        innerstr='jerry'
        matching_names=get_filenames(self.dirname,innerstr)
        self.assertEquals(3,len(matching_names))

when I run the unittest, if the test fails at the first assertion,the
other assertions are not executed at all..How do I organize the test
so that all assertions can run?

thanks
jim



More information about the Python-list mailing list