python - 未使用的导入使我可以访问信号的标准输出
问题描述
我刚刚遇到了一次奇怪的互动,我很好奇你们中的一个人能否解释发生了什么:
我正在编写一个测试,首先我创建了一个简单的打印语句来检查信号是否消失。这是位于的测试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')
这是我要测试的信号代码notifcations/notifications.py
:
@receiver(post_save, sender='core.Like')
def like_signal_post_save(sender, **kwargs):
""" Post save signal for Like model """
print("Something")
幕后发生了一些神奇的事情,但这里的目标是print("Something")
每次保存 Like 对象时。
...
现在,这就是让我感到困惑的地方。我能够让它工作,但只有在从notifications.py
我的test_notifications.py
文件中导入一个单独的函数之后。
这是导入语句:from core.services.notifications.notifications import print_test
为什么不同函数 ( print_test
) 的导入语句允许我访问标准输出?
解决方案
推荐阅读
- java - 没有发现突变 PitTest Maven
- azure-data-factory-2 - 对嵌套的 Delta 结构使用 ADF 数据流派生列转换
- typescript - 打字稿检查字符串是否作为接口键存在
- angular - 在 FontAwesome 和 Angular 10 中更改图标
- ruby-on-rails - 尝试使用 Gemoji Gem 时出现资产管道错误
- javascript - Angular 7,如何从输入导入的 srt 或 csv 文件中读取数据,并保存在数组中?
- awk - 对于使用 awk 以相同方式填充的两个数组,元素的顺序是否相同?
- ios - CORE 数据:根据对象的关系获取对象
- python - BERT 标记 URL
- python - 多个用户可以写入一个 SQLite 数据库,还是纯粹是本地的