1

I just ran into a strange interaction and I'm curious if one of you could explain what's happening:

I'm writing a test, and to start I just created a simple print statement to check if the signal was going off. Here's the test located in notifications/tests/test_notifications.py:

def test_like_post_save_signal(self):
    """ Testing the signal that is connected to the Like model's post_save. """
    baker.make('core.Like')

Here's the signal code I'm trying to test located in notifcations/notifications.py:

@receiver(post_save, sender='core.Like')
def like_signal_post_save(sender, **kwargs):
    """ Post save signal for Like model """
    print("Something")

There's a bit of magic happening behind the scenes, but the goal here is to print("Something") every time a Like object is saved.

...

Now, here's what's confusing me. I was able to get it to work, but only after importing a separate function from notifications.py into my test_notifications.py file.

Here's the import statement: from core.services.notifications.notifications import print_test

Why does an import statement of a different function (print_test) give me access to the stdout?

Bonteq
  • 777
  • 7
  • 24

0 Answers0