Adama Camara
Adama Camara

Reputation: 165

Trying to activate Django signal in my test

Hey I am trying to activate a signal in my test - but I can not seem to make it work.

This is my receiver

@receiver(post_save, sender=models.Allocation, dispatch_uid="close_overdue_invoice_tasks")

So how can "activate" it so it will call the method:

def close_overdue_invoice_tasks(sender, **kwargs):
    ...

All the signals works and my guess is that you manually have to activate the signals when running the tests.

I am using Pytest by the way.

Upvotes: 2

Views: 3105

Answers (1)

Alex
Alex

Reputation: 1522

Your signal will be called when you save your model that it is attached to. In this case, calling .save() on an instance of Allocation will cause the signal to be called.

You shouldn't have to activate the signals, they should be already set up. Check where you defined your signals and make sure that they are being executed during your test run.

Upvotes: 5

Related Questions