【发布时间】:2015-02-19 22:13:00
【问题描述】:
我有一个通过 HTTP 调用远程服务的类。现在,这个类检测它是否在“TESTING”模式下运行并采取相应的行动:在“TESTING”时它不会将实际请求发送到远程服务,它只是返回而不执行任何操作。
class PushService(object):
def trigger_event(self, channel_name, event_name, data):
if satnet_cfg.TESTING:
logger.warning('[push] Service is in testing mode')
return
self._service.trigger(channel_name, event_name, data)
几个测试调用部分代码,最终调用此方法。我的问题如下:
1. Do I have to patch this method/class for every test that, for some reason, also invoke that method?
2. Is it a good practice to try to patch it in the TestRunner?
【问题讨论】:
标签: python django unit-testing mocking