On Mar 28, 2:21 pm, "Michael Bayer" <[email protected]> wrote:
> iain duncan wrote:
> > Thanks Mike. I figured this is probably not the intended use. The
> > thing is, I'm trying to make a declarative template for test seed data
> > and declaring it all in a class like so makes for the easiest quickest
> > way of extending my fixture:
>
> > class SeedData1(SeedData):
> >   obj1 = ModelObject( ...kwargs... )
> >   obj2 = ModelObject2( ...kwargs...
>
> > This allows me to make new seed data fixtures by simply inheriting
> > from SeedData1, and makes typing up seed fixtures dead quick.
>
> I don't see what this has to do with clearing out sessions and the objects
> that are associated within.   Is SeedData1 some kind of magic class that
> persists obj1, obj2, etc. in the Session?  why can't whatever SeedData1
> does be done for each test ?

Yes, the seed class makes new objects that I want in the db as
fixture. I want to use the class as a namespace for a standard set of
fixture objects, mostly because of the ease of setting it up that
gives me, and because I can do things like make variants of the
standard fixture with a simple inherit and override. Of course the
class code gets run at import time of the class, so the objects in the
seed class are created then, with the active scoped session. However,
I want to reuse that fixture declaration over and over again, with a
fresh session and fresh tables. So when the tests start, the seed
class has created objects in the session imported from turbogears.
This session doesn't get flushed. The first test recreates the tables,
copies the seed objects into the new session for the first test,
flushes it to the db, does it's test stuff, and then wipes out that
session. Then I hit the snag because I can't recopy these objects into
another session after they have been persisted and I'd like to repeat
that process:
- drop tables
- make new session
- copy fixture objects into the new session
- flush to db
- do tests

I guess I need to either:
- wipe out the SQLA knowledget that they have been persisted
or
- clone the seed objects some how so I have new ones for each session

I thought the first would be the easiest, but maybe I'm wrong there.
If I can make sure that I have a completely fresh slate in SQLA, I
think I should be able to reimport the seedclass to use it again the
same way I do in the first test. I guess the first one works because
the original import is from  a session that never gets flushed.

thanks again for all the help!
Iain

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to