pytest-freezegun is a pytest plugin that simplifies testing time-dependent code by integrating the `freezegun` library with pytest fixtures and marks. It allows you to freeze time during test execution using either a decorator or a dedicated fixture. The current version is 0.4.2, and it maintains a moderate release cadence, addressing compatibility and feature improvements.
pip install pytest-freezegunVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the two primary ways to freeze time with pytest-freezegun: using the `pytest.mark.freeze_time` decorator for a static time freeze on a test function, and using the `freezer` fixture to dynamically control time within a test, including advancing it.
Upgrade to Python 3.6+ to use pytest-freezegun 0.4.1+.
Upgrade to pytest-freezegun 0.4.1+ or explicitly register the mark in your `pytest.ini` using `markers = freeze_time`.
Upgrade to pytest-freezegun 0.4.2+ which includes fixes for this interaction. Always ensure `freezer.move_to()` is called after `freeze_time` if dynamic adjustment is needed within a marked test.
Upgrade to pytest-freezegun 0.4.1+ for reliable support with class-based tests.
Install the package using pip: 'pip install pytest-freezegun'.
Ensure 'freezegun' is installed ('pip install freezegun') and correctly imported: 'from freezegun import freeze_time'.Provide a time string to the decorator: '@freeze_time("2023-01-01")'.Use a valid date format, such as 'YYYY-MM-DD': '@freeze_time("2023-01-01")'.Ensure 'freezegun' is installed ('pip install freezegun') and import it correctly: 'from freezegun import freeze_time'.