[Zope] FunctionalTestCase commits transactions

Peter Bengtsson peter at fry-it.com
Mon Nov 17 05:34:27 EST 2008


2008/11/17 Dieter Maurer <dieter at handshake.de>:
> Peter Bengtsson wrote at 2008-11-5 15:14 +0000:
>> ...
>>> When I wrote a functional test browser (years before "zope3"),
>>> I emulated the Zope publisher rather than calling it directly
>>> in order to have control how transactions are handled.
>>>
>>> Especially, I used subtransactions instead of top level transactions
>>> to avoid the bug reported by Peter.
>>>
>>
>>Uh? "subtransactions"?
>>So how would you recommend that I go abouts doing this?
>
> "savepoint"s have replaced subtransactions.
>
> This means:
>
>  When a request starts, a new savepoint is created.
>  When the request would cause a transaction abort (in normal operation),
>  the test request will roll back to the saved savepoint. Otherwise,
>  the modifications are kept.
>
>  When the complete test ends, the transaction is aborted, wiping out
>  all modifications done be the test. Of course, this works only when
>  all resouce managers in the transaction support savepoints (which
>  probably means that all resource managers need to be ZODB connections).
>
That's fine. When I used SQL connections in ZopeTestCase they are
aborted and after running all tests my tables are empty as expected.
With FunctionalTestCase this is not the case. It seems to have to
commit transactions (save savepoints).

I solved my situation by writing a custom tearDown() method that
manually resets the tables. Kind of like this:

class TestFunctionalBase(ZopeTestCase.FunctionalTestCase):
    def tearDown(self):
          sql = 'TRUNCATE TABLE table1, table2, table3;'
          self.pypgsqlda.manage_test(sql)
          import transaction
          transaction.commit()
          super(TestFunctionalBase, self).tearDown()

>
>
> --
> Dieter
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
>



-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list