I want to make sure two datetime objects have the same date and time up to the seconds.
from datetime import datetime
time_a = datetime(2020, 4, 29, 3, 14, 15, 9)
time_b = datetime(2020, 4, 29, 3, 14, 15, 10)
I can't just do assert time_a == time_b
, since they have different microseconds.
I could do this with multiple assert statements:
assert time_a.year == time_b.year
assert time_a.month == time_b.month
assert time_a.day == time_b.day
assert time_a.hour == time_b.hour
assert time_a.minute == time_b.minute
assert time_a.second == time_b.second
But this is a bit repetitive. Is there a more concise way to do this?