尝试在我的测试中激活 Django 信号
Trying to activate Django signal in my test
嘿,我正在尝试在我的测试中激活一个信号 - 但我似乎无法让它工作。
这是我的接收器
@receiver(post_save, sender=models.Allocation, dispatch_uid="close_overdue_invoice_tasks")
那么"activate"它怎么会调用方法:
def close_overdue_invoice_tasks(sender, **kwargs):
...
所有信号都有效,我的猜测是您必须在 运行 测试时手动激活信号。
顺便说一句,我正在使用Pytest。
当您保存信号所附加的模型时,您的信号将被调用。在这种情况下,在 Allocation
的实例上调用 .save()
将导致调用信号。
您不必激活信号,它们应该已经设置好了。检查您定义信号的位置并确保它们在您的测试期间被执行 运行.
嘿,我正在尝试在我的测试中激活一个信号 - 但我似乎无法让它工作。
这是我的接收器
@receiver(post_save, sender=models.Allocation, dispatch_uid="close_overdue_invoice_tasks")
那么"activate"它怎么会调用方法:
def close_overdue_invoice_tasks(sender, **kwargs):
...
所有信号都有效,我的猜测是您必须在 运行 测试时手动激活信号。
顺便说一句,我正在使用Pytest。
当您保存信号所附加的模型时,您的信号将被调用。在这种情况下,在 Allocation
的实例上调用 .save()
将导致调用信号。
您不必激活信号,它们应该已经设置好了。检查您定义信号的位置并确保它们在您的测试期间被执行 运行.