python - How to mock/set system date in pytest? -


in of tests having problem fail on travis because of time , time zone problems, want mock system time test. how can this?

afaik, can't mock builtin methods.

one approach have done change code bit not use datetime directly obtain date, wrapper function somewhere:

# mymodule.py  def get_today():    return datetime.date.today() 

this makes trivial mock in test:

def test_something():     mock.patch('mymodule.get_today', return_value=datetime.date(2014, 6, 2)):         ... 

you can use freezegun module.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -