Testing Signals

12 views
Skip to first unread message

Grant Means

unread,
Aug 11, 2015, 2:57:03 PM8/11/15
to Django users
I have an app that fires a custom signal when a specific method is called. 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!
Reply all
Reply to author
Forward
0 new messages