Instead of doing
def do_something_with_date(): now = datetime.now() return now - timedelta(days=2)
def do_something_with_date(now): return now - timedelta(days=2)
Alternatively, if you're using Python, use the freezegun library to fix the current time in tests: https://github.com/spulec/freezegun
Instead of doing
you should do and explicitly pass in edge-case dates into the `now` param in your unit tests.Alternatively, if you're using Python, use the freezegun library to fix the current time in tests: https://github.com/spulec/freezegun