How to organize test cases with PyUnit

Peter Hansen peter at engcorp.com
Sun Jul 7 23:40:02 EDT 2002


Roy Smith wrote:
> 
> class dictionaryEntries (parserTestCase):
>     def runTest (self):
>         tables = self.parser.parse ('data/rulex.envmon')
>         self.assertEqual (type (tables), DictType)
>         self.assertEqual (1, 0)
>         for table in tables:
>             print type(table)
>             self.assertEqual (type (table), DictType)
> 
> if __name__ == "__main__":
>     dictionaryEntries().run()
> ====================================
> 
> parser.parse() is supposed to (and does) return a dictionary of
> dictionaries.  The line "for table in tables:" should read "for table in
> tables.keys():".  As written, it should raise a TypeError.  In the
> process of trying to figure out why it wasn't, I added the "print
> type(table)" line, and it doesn't print anything.  Then I added the
> "assertEqual (1, 0)", and it still does nothing.
> 
> Obviously, I'm doing something wrong.  I suspect something has wrapped
> my methon in a try block that catches all these exceptions, but then
> doesn't do anything with them.

Not sure, but you might try this instead.  Rename the runTest()
method to start with the text "test", and then change the __main__
content to be simply 'unittest.main()' instead of the dictEntries.run
that you have.

PyUnit not only supports various command line options for you this
way, but it also finds all 'testXXX' methods automatically and it
shouldn't give the above behaviour.

-Peter



More information about the Python-list mailing list