I am running test for my project in Python and all of them passed, excepted one.
Here is the code of the function:
@botcmd
def reminder_next():
today = datetime.now()
return "\n".join(
f"Next planning: {Reminder.next_occurance('Sprint planning', today)}",
f"Next daily: {Reminder.next_daily(datetime.now(timezone), today)}",
f"Next review: {Reminder.next_occurance('Sprint review', today)}",
f"Next retrospective: {Reminder.next_occurance('Sprint restrospective', today)}"
)
And the code of the test:
@freeze_time("2023-06-12", tz_offset=2)
def test_reminder_next():
expected_response = "\n".join([
f"Next planning: {datetime(2023, 6, 19, 15, 30, tzinfo=timezone_utc2)}",
f"Next daily: {datetime(2023, 6, 13, 9, 30, tzinfo=timezone_utc2)}",
f"Next review: {datetime(2023, 6, 15, 14, 45, tzinfo=timezone_utc2)}",
f"Next retrospective: {datetime(2023, 6, 16, 9, 30, tzinfo=timezone_utc2)}"
])
assert Reminder.reminder_next() == expected_response
And the error:
TypeError: tzinfo argument must be None or of a tzinfo subclass, not type 'type'
By the way timezone_utc2
is defined by timezone_utc2 = pytz.timezone('Etc/GMT+2')
(pytz is imported)
I tried replacing timezone_utc2
by Etc/GMT+2
: instead of 'type' at the end of the error, I got 'str'.
I tried without anything and it doesn't work either.
If the test is correct, I should have a green bar with '7 passed in x seconds' (I have 6 other tests which are correct)
try to use timezone_utc2.localize https://pypi.org/project/pytz/
@freeze_time("2023-06-12", tz_offset=2)
def test_reminder_next():
expected_response = "\n".join([
f"Next planning: {timezone_utc2.localize(datetime(2023, 6, 19, 15, 30))}",
f"Next daily: {timezone_utc2.localize(datetime(2023, 6, 13, 9, 30))}",
f"Next review: {timezone_utc2.localize(datetime(2023, 6, 15, 14, 45))}",
f"Next retrospective: {timezone_utc2.localize(datetime(2023, 6, 16, 9, 30))}"
])
assert Reminder.reminder_next() == expected_response