我有以下内容:
from datetime import datetime
def get_report_month_key():
month_for_report = datetime.utcnow()
return month_for_report.strftime("%Y%m")
我如何模拟 datetime.utcnow() 以便我可以对此函数编写单元测试?
尝试阅读这篇文章 , 但我无法在 utcnow() 上为我工作
原文由 Steven Yong 发布,翻译遵循 CC BY-SA 4.0 许可协议
在你的测试文件中: