iain duncan wrote:
>
>
>
> On Mar 28, 2:21 pm, "Michael Bayer" <mike...@zzzcomputing.com> 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 think the best way is to create a function that gives you new objects,
and is loaded in during the setup() for your tests.  its the same amount
of typing as declaring them module-wide.    the second way is to clone the
objects or create them from some kind of state, like dicts.   the third,
merge() them into the session - the original objects will be unchanged. 
fourth, and this is the most hacky way of all, "from sqlalchemy.orm import
attributes;  del attributes.instance_state(instance).key".   you'd have to
do that on all objects in the whole graph which you want to reuse.   i
don't see that as being any easier than just cloning them.

--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to