Joost Moesker wrote:
> The setup and tearDown methods on testutils.DBTest automatically
> create and drop the database schema per testcase.

DBTest is SQLObject-specific

In my case (with sqlalchemy) I cannot drop and recreate the schema for
each test because it would take too much time -- the schema is
postgres-specific, autoloaded, and has triggers, bells and whistles.

I've come up with this:

> class DBTestCase(unittest.TestCase):
>     transaction = None
>
>     def setUp(self):
>         # In case of errors, we cleare here the session and
> transaction, or other tests will fail
>         if self.transaction:
>             self.transaction.rollback()
>             self.transaction = None
>         session.clear()
>
>         self.transaction = session.create_transaction()
>
>     def tearDown(self):
>         # Hit the db before rollback
>         # This way, we catch some integrity errors, type checking from
> sqlalchemy, and the like
>         session.flush()
>         self.transaction.rollback()
>         self.transaction = None
>         session.clear()

Works for me.
The first session.clear() is suspicious, but I had no time to
investigate yet





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

Reply via email to