Hi everyone. Not sure if this is the right forum ...
# ask-community
s
Hi everyone. Not sure if this is the right forum for this question but let me give it a try. I want to setup a 45 day schedule where I would run a set of tasks each day. My question is how do I go about testing this? I would like to "change" the date each pass in a loop controlling the test. I could not not find any guidance how to test something like this 45 day schedule in an easy way without running it for 45 days. I was originally trying IntervalClock or DatesClock. I assume there is an easier way but could not find anything. Any guidance is most appreciated!!
z
Hi @Steve Aby -- the date in the context is generated with
Copy code
now = pendulum.now("utc")
        dates = {
            "date": now,
            "today": now.strftime("%Y-%m-%d"),
            "yesterday": now.add(days=-1).strftime("%Y-%m-%d"),
            "tomorrow": now.add(days=1).strftime("%Y-%m-%d"),
            "today_nodash": now.strftime("%Y%m%d"),
            "yesterday_nodash": now.add(days=-1).strftime("%Y%m%d"),
            "tomorrow_nodash": now.add(days=1).strftime("%Y%m%d"),
        }
to test different dates you can monkeypatch the result of
pendulum.now()
or because these are set with
setdefault
e.g.
Copy code
for key, val in dates.items():
            context.setdefault(key, val)
you can just set the date in the context beforehand and it will not be overridden
s
Thanks Michael....easy answer and sorry for not thinking of that
z
I had to look at the code to sort it out myself so don't worry about it 🙂