Simulating the passing of time in unittesting

后端 未结 3 1980
醉话见心
醉话见心 2021-02-04 03:25

I\'ve built a paywalled CMS + invoicing system for a client and I need to get more stringent with my testing.

I keep all my data in a Django ORM and have a bunch of Cele

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 03:58

    You can also take a look at freezegun module. Github - https://github.com/spulec/freezegun

    From their docs

    from freezegun import freeze_time
    import datetime
    
    
    @freeze_time("2012-01-14")
    def test():
        assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
    

提交回复
热议问题