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 <[email protected]> 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 <[email protected]> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to