首页
Python
Java
PHP
IOS
NodeJS
JavaScript
HTML5
小程序
AI
freezegun
全部标签
python - 如何在 pytest 中模拟/设置系统日期?
在我的一些测试中,由于时间和时区问题,它们在Travis上失败了,所以我想为我的测试模拟系统时间。我该怎么做? 最佳答案 @Brian-Kruger的回答是最好的。我已投票取消删除它。同时...使用freezegun(repo)。自述文件:fromfreezegunimportfreeze_time@freeze_time("2012-01-14")deftest():assertdatetime.datetime.now()==datetime.datetime(2012,1,14)
何在
python
section
freezegun
datetime
pytest
python - 使用 freezegun,为什么 pytz.utc 和 utcnow() 输出不同的日期时间?
我很困惑,为什么使用freezegun卡住时间的函数会输出不同的UTC时间,具体取决于调用的是datetime.datetime.utcnow()还是datetime.datetime.now(pytz.utc)。我并不是说它坏了,只是我不明白为什么,我想知道!例如,使用这个函数:@freeze_time("2012-01-1403:21:34",tz_offset=-4)deftest():print("utcnow():%s"%datetime.datetime.utcnow())print("pytz.utc:%s"%datetime.datetime.now(pytz.utc)
freezegun
python
datetime
code
section
pytz
Home
Powered By IT.CAOLU.XIN
页面耗时:0.0632s