skillfed

pytest-freezegun

Wrap tests with fixtures in freeze_time

pytest-freezegun v0.4.2 1.4M downloads/30d#3,899 on PyPI196
Permissive license MIT Abandoned released

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-freezegun

uv

uv add pytest-freezegun

poetry

poetry add pytest-freezegun

Installing 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

Development Status :: 4 - BetaFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing

Tags

pytest time freezingmock time in testsfreeze time pytest fixturecontrol system clock testsdatetime mocking pytesttime travel testingfreezegun pytest plugin
pytest-plugintime-mockingtest-fixtures

More Testing packages