Time related issues are tricky part in software engineering. So they require proper testing.
Few ideas how to tackle testing time related part of code:
- parametrize tested methods/functions with explicit time passed - sometimes a bit kind of test-only usage, because inside anyway datetime.now() is used
- using specialized library like freezgun for efficent time mocks
Two major options to use freezgun in your tests:
other cool things
- support for timezones
- support for manual ticking and auto ticking with delta