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.)
精彩评论