how to make all assertions in a unit test execute
Peter Otten
__peter__ at web.de
Sat Oct 16 04:44:12 EDT 2010
jimgardener wrote:
> 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'
> 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?
Keep it simple ;)
def test_get_filenames_single_match(self):
> innerstr='tom'
> matching_names=get_filenames(self.dirname,innerstr)
> self.assertEquals(1,len(matching_names))
def test_get_filenames_no_match(self):
> innerstr='myself'
> matching_names=get_filenames(self.dirname,innerstr)
> self.assertEquals(0,len(matching_names))
def test_get_filenames_multi_match(self):
> innerstr='jerry'
> matching_names=get_filenames(self.dirname,innerstr)
> self.assertEquals(3,len(matching_names))
Peter
More information about the Python-list
mailing list