pytest-freezegun
Wrap tests with fixtures in freeze_time
What it is and what it does
pytest-freezegun is a pytest plugin that integrates freezegun's time-freezing capability into the pytest testing framework. It provides a `freezer` fixture that you can inject into test functions to freeze and manipulate the system clock, and a `@pytest.mark.freeze_time` decorator for marking tests that should run with time frozen. This is useful when testing code that depends on the current date or time—you can freeze time at a specific moment, advance it, or move to a different date entirely, all within a single test, ensuring reproducible and deterministic behavior.
The plugin works with both function-based and class-based tests, integrates with other fixtures, and allows you to pass arguments to freezegun via the decorator. Because it depends on freezegun and pytest, you need both installed. The package is no longer actively maintained, with the last release in 2020 and no updates since then, so it may have compatibility issues with recent versions of pytest or Python.
Use it for:
- Test code that checks if a deadline has passed by freezing time at a specific date and asserting the expected behavior.
- Verify that scheduled tasks trigger correctly by advancing frozen time and checking task execution.
- Test time-dependent calculations (e.g., age, interest accrual) by setting the clock to known dates.
- Ensure that retry logic with exponential backoff works as expected by controlling time progression.
- Test timezone-aware datetime handling by freezing time at specific moments across different zones.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
pytest-freezegun provides a pytest plugin that freezes time in tests using freezegun, allowing you to control the system clock within test functions and fixtures.
Yes, if your project is on a stable pytest and Python version and you need straightforward time-freezing in tests. No, if you require active maintenance or compatibility with recent pytest/Python releases—the package is abandoned and may break with newer versions. Consider it a low-risk, low-friction addition to an established test suite, but not a foundation for new projects expecting long-term support.
Install
pytest-freezegun on PyPI
pip
pip install pytest-freezegunuv
uv add pytest-freezegunpoetry
poetry add pytest-freezegunInstalling pytest-freezegun
Before you install
Low install friction with only two runtime dependencies (freezegun and pytest). However, the package is abandoned—last release was 2020-07-19 and last commit 2023-03-28—so it will not receive bug fixes or updates for newer Python or pytest versions.
License in practice
MIT license is permissive; you can use this package freely in commercial and private projects with minimal restrictions, though you must include the license notice.
Quickstart
pip install pytest-freezegun
import pytest
from datetime import datetime
def test_frozen_date(freezer):
now = datetime.now()
freezer.move_to('2017-05-20')
later = datetime.now()
assert now != later
Verify before relying
- Whether the package works reliably with pytest versions released after 2020-07-19
- Compatibility with Python versions beyond 3.8 (classifiers list only up to 3.8)
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — freezegun, pytest |
| Maintenance | abandoned — 2,217 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,437,061/month — #3,899 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_freezegun-0.4.2-py2.py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
freezegunFreezeGun mocks Python's datetime and time…
permissive · top 1,000 on PyPI
pytest-freezerpytest-freezer provides a pytest fixture that…
permissive · top 5,000 on PyPI
time-machineMocks and freezes time in tests, allowing you…
permissive · top 1,000 on PyPI
pytest-socketA pytest plugin that blocks or restricts socket…
permissive · top 5,000 on PyPI
pytest-pgsqlA pytest plugin that provides fixtures for…
permissive · top 15,000 on PyPI
pytest-datafilesA pytest plugin that copies specified files and…
permissive · top 15,000 on PyPI
pytest-replayA pytest plugin that records test execution…
permissive · top 15,000 on PyPI
pytest-loggingA pytest plugin that configures Python logging…
permissive · top 15,000 on PyPI
pytest-threadleakA pytest plugin that detects when tests leak…
permissive · top 15,000 on PyPI
pytest-regressionsProvides pytest fixtures for writing regression…
permissive · top 5,000 on PyPI