Testing Signals

58 views
Skip to first unread message

Grant Means

unread,
Aug 14, 2015, 5:43:36 PM8/14/15
to Django developers (Contributions to Django itself)
I posted this in Django users but didn't get any reply. I hope you don't mind me asking here. I does involve Django internals.

Simply put, I have an app that has a model that's consumed by other "pluggable" apps. This model will send certain signals during certain events that the pluggable apps can consume and respond to.

I'd like to test that my model indeed sends the expected signal during specific actions. I wrote a test that connects to the signal in setUp() and uses a local listener function to set a class attribute to True if the handler is called. You can see the relevant code here:


This works fine if I test the module directly using ./manage.py test <app> test_models.py. However if I run test <app> or simply test the signals don't appear to connect. Using PyCharm I stepped through the code and found that when I call .connect() in my TestCase, and step into Signal.connect() I can see all of the expected receivers on `self.receivers`. 

However if I step into the Signal.send() method when the signal is fired, none of the expected receivers are in place. Again, this works if I test the module directly just not if I use `test <app>` or `test`. 

Does anyone have any guidance on how I could get this to work? Thanks!

Jeremy Dunck

unread,
Aug 14, 2015, 5:58:52 PM8/14/15
to django-d...@googlegroups.com
I suspect you have 2 different definitions of the signal under different import paths.  Ensure your python path doesn't have overlapping directories, and that your signal imports refer to the same sys.modules key (e.g. some_app.signals.foo all over, not proj.some_app.signals.foo and some_app.signals.foo in various places).

This might help troubleshoot:





--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6d8a3d9b-b04b-4a08-93c4-8363834e41b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Graham

unread,
Aug 14, 2015, 8:49:13 PM8/14/15
to Django developers (Contributions to Django itself)
Hi Grant, for future reference django-developers isn't meant as a second level support channel if you don't get a reply on -users. Thanks!
Reply all
Reply to author
Forward
0 new messages