[TIP] database regression testing

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Apr 9 16:11:00 PDT 2008

"Kumar McMillan" <kumar.mcmillan at gmail.com> writes:

> On Wed, Apr 9, 2008 at 9:41 AM, Nate Lowrie <solodex2151 at gmail.com> wrote:
> > Do we have something similar to SQLUnit in Python? Any
> > recommendations?
> The way I have done what SQLUnit does in Python is for my suite to
> create a test database (yes a real one), load up some data in setUp(),
> call the stored procedure, make some selects to assert it did the
> right thing, then delete the data in tearDown().

I do a similar thing, but simply have each test case do its work in a
transaction that is always rolled back afterward, so I don't have to
explicitly delete data after each test.

That is, the TestCase.setUp() performs an SQL BEGIN, and the
TestCase.tearDown() performs an SQL ROLLBACK. These methods are on a
custom TestCase that I then use as the base class for all my database
unit tests.

For the topic of agile development of databases, I highly recommend
the book "Refactoring Databases" by Pramod Sadalage

It is divided into two parts: five chapters on the topic of an agile
approach to developing the database, and the bulk of the book giving
details of atomic refactorings to an existing database schema. Don't
be fooled by the website's focus on that latter part (listing all the
individual refactorings): that's reference material. The meat of the
book is in its first section, worth the asking price.

 \          "When we call others dogmatic, what we really object to is |
  `\        their holding dogmas that are different from our own."  -- |
_o__)                                                   Charles Issawi |
Ben Finney

More information about the testing-in-python mailing list