【发布时间】:2016-01-26 13:33:08
【问题描述】:
我正在尝试测试以下代码:
great_report.py
from retry import retry
@retry((ReportNotReadyException), tries=3, delay=10, backoff=3)
def get_link(self):
report_link = _get_report_link_from_3rd_party(params)
if report_link:
return report_link
else:
stats.count("report_not_ready", 1)
raise ReportNotReadyException
我有我的测试函数,它模拟 _get_report_link_from_3rd_party 测试所有内容,但我不希望这个函数在我运行测试期间实际暂停执行..
@mock.patch('repo.great_report._get_report_link_from_3rd_party', return_value=None)
test_get_link_raises_exception(self, mock_get_report_link):
self.assertRaises(ReportNotReadyException, get_link)
我尝试模拟重试参数,但遇到了 get_link 不断重试的问题,这会导致构建时间过长,而不仅仅是引发异常并继续。如何在我的测试中模拟 @retry 调用的参数?
【问题讨论】:
标签: python unit-testing mocking