开发者

In test cases(unit-testing), Django pre_save signal can not be caught

In Django, my code on catching pre_save signal works well. However, in testcases in tests.py, the signal handler cannot receive anything. Is there any hint for this problem?

  • It seems that my testcases and signal h开发者_开发百科andler are in different apps. Is this the cause of the problem?


It seems that my testcases and signal handler are in different apps. Is this the cause of the problem?

Yes. Each app's tests.py is atomic. import your signal registration code or connect them manually somewhere in your test to make sure they are listening:

You can put signal handling and registration code anywhere you like. However, you'll need to make sure that the module it's in gets imported early on so that the signal handling gets registered before any signals need to be sent.

(From: Listening to signals, Connecting receiver functions.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜