meta.create_all() and meta.drop_all() are helpful too.  and the nose
module [1] makes it easy to setup/teardown a package of tests since
you can define setup() and teardown() in an __init__.py

[1] http://somethingaboutorange.com/mrl/projects/nose/

On 2/2/07, Christopher Arndt <[EMAIL PROTECTED]> wrote:
>
> Allen schrieb:
> > How do people writing db applications with SA do unit testing on their
> > code?  Are there any good db unit testing frameworks that work well
> > with SA?  If I can't find anything I will probably just roll my own
> > but I would like to keep from reinventing the wheel if I can help it.
>
> Basically you have to initialize your database for each test and destroy it
> afterwards again (otherwise it wouldn't be a 'unit' test). In the 'unittest'
> module, you can use the 'setUp' and tearDown' methods of the TestCase class 
> for
> this purpose.
>
> For example:
>
> # model contains the SA table and mapper classes
> import unittest
> import sqlalchemy
> import model
>
> class SATestCase(unittest.TestCase):
>
>     def setUp(self):
>         # do what you have to do to bind the metadata/engine to the model here
>
>         # create all model tables
>         for item in dir(self.model):
>             item = getattr(self.model, item)
>             if isinstance(item, sqlalchemy.Table):
>                 item.create(checkfirst=True)
>
>     def tearDown(self):
>         # drop all model tables
>         for item in dir(self.model):
>             item = getattr(self.model, item)
>             if isinstance(item, sqlalchemy.Table):
>                 item.drop(checkfirst=True)
>         # close database
>
>     def testFoo(self):
>         # here comes your unit test
>
>
> Chris
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to