def now(cls):
    return FAKE_TIME
monkeypatch.setattr(datetime, 'datetime', mydatetime)

def test_patch_datetime(patch_datetime_now):
    assert datetime.datetime.now() == FAKE_TIME
How to monkeypatch python's datetime.datetime.now with py.test?