@decorator
def assert_signal_called(signal, **expected):
 handler = Mock()
 def on_call(**kwargs):
  return handler(**kwargs)
 signal.connect(on_call)
 try:
  (yield handler)
 finally:
  signal.disconnect(on_call)
 handler.assert_called_with(signal=signal, **expected)

@ decorator def assert_signal_called ( signal , ** expected ) : handler = Mock ( ) def on_call ( ** kwargs ) : return handler ( ** kwargs ) signal . connect ( on_call ) try : ( yield handler ) finally : signal . disconnect ( on_call ) handler . assert_called_with ( signal = signal , ** expected )
context that verifes signal is called before exiting .