Marked as helpful by the asker
Your test encodes local time as truth. Make the code and the test both explicit:
from datetime import datetime, timezone
now = datetime.now(timezone.utc)and in tests, freeze time with freezegun or pass now in as a parameter. A function that reads the wall clock is untestable; a function that receives the time is trivial.