【发布时间】:2017-06-23 00:08:21
【问题描述】:
以下是我的代码:并且需要测试 myfunction()。以及如何创建文件的模拟函数。
def myfunction(self):
with tempfile.NamedTemporaryFile() as tf:
f.seek(0)
tf.write(f.read())
tf.flush()
ocr_content_dict = self.ocr.ocr_document(tf.name, mimetype) or ''
ocr_content = ocr_content_dict['content']
【问题讨论】:
-
这能回答你的问题吗? Python: Mocking a context manager
标签: python python-2.7 unit-testing mocking