def capture_mails(self): mails = [] def on_mail_sent(mail): mails.append(mail) mail_sent.connect(on_mail_sent) yield mails mail_sent.disconnect(on_mail_sent)