Thanks, I'll try to make it work with the latter method somehow. Clearing all session event listeners is not an option because some of the code under test relies on a permanent listener being there.
keskiviikko, 11. syyskuuta 2013 21.15.46 UTC+3 Michael Bayer kirjoitti: > > you can either remove all the listeners for a certain type, like this: > > events.MapperEvents._clear() > > the other alternative is wrap your events with a set that you control: > > my_listeners = set() > > @event.listens_for(target, "whatever") > def evt(target): > for listener in my_listeners: > listener(target) > > > > On Sep 11, 2013, at 1:44 PM, Alex Grönholm > <alex.g...@nextday.fi<javascript:>> > wrote: > > Thanks for the quick reply. I don't want to use prerelease versions of > SQLAlchemy though. Is there any recommended way of doing this in 0.8.2? > > keskiviikko, 11. syyskuuta 2013 20.40.40 UTC+3 Michael Bayer kirjoitti: >> >> >> On Sep 11, 2013, at 1:16 PM, Alex Grönholm <alex.g...@nextday.fi> wrote: >> >> > I'm trying to test code that listens to session events on all sessions. >> I can't pin it on any particular session or even sessionmaker due to the >> architecture of the software (sessions are explicitly instantiated on the >> fly). >> > All is well except that the listener sticks after the test is done, >> breaking test isolation. The ideal solution would be to unregister the >> listener in teardown(), but I don't see anything in the event API that >> could be used to do that. >> >> the public API is in 0.9 (of course there are crude hacks in 0.8) : >> http://docs.sqlalchemy.org/en/latest/changelog/migration_09.html#event-removal-api >> >> >> >> > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+...@googlegroups.com <javascript:>. > To post to this group, send email to sqlal...@googlegroups.com<javascript:> > . > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.