@contextmanager
def mock_signal_receiver(signal, wraps=None, **kwargs):
 if (wraps is None):
  def wraps(*args, **kwargs):
   return None
 receiver = Mock(wraps=wraps)
 signal.connect(receiver, **kwargs)
 (yield receiver)
 signal.disconnect(receiver)

@ contextmanager def mock_signal_receiver ( signal , wraps = None , ** kwargs ) : if ( wraps is None ) : def wraps ( * args , ** kwargs ) : return None receiver = Mock ( wraps = wraps ) signal . connect ( receiver , ** kwargs ) ( yield receiver ) signal . disconnect ( receiver )
temporarily attaches a receiver to the provided signal within the scope of the context manager .