DEV Community

Nitin Sijwali
Nitin Sijwali

Posted on

Your tests pass today. Will they pass on Feb 29?

pytest-calendar-chaos catching a month-end bug

Some date bugs only show up on specific days: Feb 29, the last day of a month, New Year's Eve, a DST change. You can't wait for those dates to test them, so the bugs ship.

pytest-calendar-chaos runs a marked test once for each of those moments, with the clock frozen using time-machine:

@pytest.mark.calendar_chaos(
    cases=["leap_day", "month_end", "dst"], zones=["UTC", "America/New_York"]
)
def test_subscription_renewal(): ...
Enter fullscreen mode Exit fullscreen mode

The presets cover leap day, month end, year end, midnight, ISO week 53, the 2038 limit and DST changes. When a case fails, the report shows the exact mocked time and a command that reruns only that scenario. It's opt-in, so unmarked tests don't change.

pip install pytest-calendar-chaos
Enter fullscreen mode Exit fullscreen mode

It needs Python 3.10+ and pytest 8+. It's MIT licensed and at version 0.3.0 on PyPI. It's a small project, so bug reports are the most useful thing you can send me.

Repo: https://github.com/nsijwali/pytest-calendar-chaos

Top comments (0)