【发布时间】:2013-04-13 07:10:00
【问题描述】:
我想确保 datetime.datetime.now() 返回一个特定的日期时间以用于测试目的,我该怎么做?我试过pytest的monkeypatch
monkeypatch.setattr(datetime.datetime,"now", nowfunc)
但这给了我错误TypeError: can't set attributes of built-in/extension type 'datetime.datetime'
【问题讨论】:
标签: python unit-testing datetime monkeypatching pytest