Python and database unittests

M.-A. Lemburg mal at egenix.com
Wed Aug 27 06:33:31 EDT 2008


On 2008-08-26 23:35, Daniel wrote:
> Hello,
> 
> I'm writing an application that interacts with a database.  As I think
> about how to write the unittests, I want them to be able to run
> without actually having to access a live database.  The pattern that
> best describes this is here:
> 
> http://martinfowler.com/eaaCatalog/serviceStub.html
> 
> I have found http://qualitylabs.org/pdbseed/, which helps with
> unittests for a live database.  This isn't what I'm after.
> 
> Does anyone know about a module that acts as a database stub for
> python unittests?

I'm not sure how such a stub would help in testing. After all, you
want the unit tests to work against the real database in order to
find possible bugs in the way you use that database. A stub would
only hide possible bugs due to incorrect usage of database APIs
(or possibly even cause fake ones due to bugs in the stub).

When testing database applications, it's usually best to have
a separate test installation of the whole system which then
creates a test dataset at testing setup time and eventually
cleans up the database again after all tests have run.

For small tests and depending on the database backend, you can
often put all the setup, testing of the database into
a single transaction, so you don't even have to bother with
the removal step (just roll back your changes at the end of the
test).

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Aug 27 2008)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611



More information about the Python-list mailing list