[FRPythoneers] Doctest

Steve Purcell stephen_purcell at yahoo.com
Thu Jul 26 02:26:59 MDT 2001


Sean Reifschneider wrote:
> Sure, but then for every test you have to make it a function and register
> that function with with the test suite using addTest().
> 
> unless I'm missing something...
> 
> When Evelyn was first explaining PyUnit to me, the first thing I thought
> was that it looked at the attributes and automatically ran any that had
> "test_" or something in the name.


Correct! If you name all your test methods 'testXXX' (or 'test_XXX' if
you prefer) then they can be found automatically. The easiest way to
accomplish this is to add the following at the bottom of the module
containing your tests:

   if __name__ == '__main__':
       unittest.main()

This finds and runs all the test cases in the current module.

If you want to create a TestSuite comprising all the possible test methods
of a TestCase subclass, use a TestLoader. The simplest way is:

   mysuite = unittest.defaultTestLoader.loadTestsFromTestCase(MyTestCase)

or for all the tests in a module:

   mysuite = unittest.defaultTestLoader.loadTestsFromModule(mytestmodule)


> Why do you prefer not having non-fatal test failures?

Because if you keep test methods short and independent, and do the above to
find and run them, it's simpler, and non-fatal test failures aren't required.

Best wishes,

-Steve

-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Test your web apps with http://webunit.sourceforge.net/



More information about the FRPythoneers mailing list