想要在Django测试中禁用信号 [英] Want to disable signals in Django testing
本文介绍了想要在Django测试中禁用信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我有各种信号和处理程序,这些信号和处理程序是跨应用程序发送的。但是,当我执行测试/进入测试模式时,我希望禁用这些处理程序。
So I have various signals and handlers which are sent across apps. However, when I perform tests / go into 'testing mode', I want these handlers to be disabled.
是否存在Django特定的禁用信号/处理程序的方式?在测试模式下?我可以想到一种非常简单的方法(将处理程序包含在if TESTING子句中),但是我想知道Django中是否内置了更好的方法?...
Is there a Django-specific way of disabling signals/handlers when in testing mode? I can think of a very simple way (of including the handlers within an if TESTING clause) but I was wondering if there was a better way built into Django?...
推荐答案
不,没有。您可以轻松地建立条件连接:
No, there is not. You can easily make a conditional connection though:
import sys
if not 'test' in sys.argv:
signal.connect(listener, sender=FooModel)
这篇关于想要在Django测试中禁用信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文