Kumar McMillan wrote:
> Hello, I have not been able to figure this out from the docs.
> 
> I would like to setup and teardown test data using mapped classes.
> The problem is that those same mapped classes need to be used by the
> application under test and in case there is an error, the teardown
> still needs to run so that subsequent tests can setup more data.  It
> seemed like the setup/teardown could be accomplished with a privately
> scoped session but what I see is that this "private" session collides
> with that of the application.  Here is a failing test case (also
> attached) that illustrates exactly what I need to do (sorry it's a
> little long).  The reason it catches the IntegrityError is because
> during testing any kind of error can happen and I need to teardown
> data regardless.  Should I give up and use insert statements and
> engine objects for the setup/teardown?  Or is there a way to make this
> test case pass?  I am using sqlalchemy 0.4.2p3

You're stepping on yourself here with sqlite- you have two transactional 
sessions, but an in-memory SQLite database only allows one connection 
and it and it's underlying transactional state is being shared by both 
sessions.  Specifically, the app_session.close() is rolling back the 
uncommited row flushed by fixture_session.flush().

This setup will work almost as-is when testing against a 
multi-connection database- you just need to commit() your fixture data 
after that flush() so that it will be visible to the "app" part of the test.

That will get this going for sqlite as well but you'd want to think 
through what a single connection shared between setup/teardown and test 
execution means to your tests.

--~--~---------~--~----~------------~-------~--~----~
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