@contextmanager
def mocked_today(self, forced_today):
    ' Helper to make easily a python "with statement" mocking the "today" date.\n        :param forced_today:    The expected "today" date as a str or Date object.\n        :return:                An object to be used like \'with self.mocked_today(<today>):\'.\n        '
    if isinstance(forced_today, str):
        forced_today_date = fields.Date.from_string(forced_today)
        forced_today_datetime = fields.Datetime.from_string(forced_today)
    elif isinstance(forced_today, datetime.datetime):
        forced_today_datetime = forced_today
        forced_today_date = forced_today_datetime.date()
    else:
        forced_today_date = forced_today
        forced_today_datetime = datetime.datetime.combine(forced_today_date, datetime.time())

    def today(*args, **kwargs):
        return forced_today_date
    with patch.object(fields.Date, 'today', today):
        with patch.object(fields.Date, 'context_today', today):
            with patch.object(fields.Datetime, 'now', return_value=forced_today_datetime):
                (yield)
Helper to make easily a python "with statement" mocking the "today" date.
:param forced_today:    The expected "today" date as a str or Date object.
:return:                An object to be used like 'with self.mocked_today(<today>):'.
@contextmanager
def mocked_today(self, forced_today):
    ' Helper to make easily a python "with statement" mocking the "today" date.\n        :param forced_today:    The expected "today" date as a str or Date object.\n        :return:                An object to be used like \'with self.mocked_today(<today>):\'.\n        '
    if isinstance(forced_today, str):
        forced_today_date = fields.Date.from_string(forced_today)
        forced_today_datetime = fields.Datetime.from_string(forced_today)
    elif isinstance(forced_today, datetime.datetime):
        forced_today_datetime = forced_today
        forced_today_date = forced_today_datetime.date()
    else:
        forced_today_date = forced_today
        forced_today_datetime = datetime.datetime.combine(forced_today_date, datetime.time())

    def today(*args, **kwargs):
        return forced_today_date
    with patch.object(fields.Date, 'today', today):
        with patch.object(fields.Date, 'context_today', today):
            with patch.object(fields.Datetime, 'now', return_value=forced_today_datetime):
                (yield)