AFAIK, you cannot make fun of built-in methods.
One approach that I often did was to modify my code a bit so as not to use datetime directly to get the date, but somewhere a wrapper function:
# mymodule.py def get_today(): return datetime.date.today()
This makes it trivial only to mock it in your test:
def test_something(): with mock.patch('mymodule.get_today', return_value=datetime.date(2014, 6, 2)): ...
You can also use the freezegun module.
source share