Install & Compatibility
Where this runs
tested against v0.4.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 32.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.9s · import 0.000s · 33MB
31MB installed
● package 31MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
freezer
✓ def test_my_feature(freezer):
# Use the freezer fixture directly
✗ from pytest_freezer import freezer
The `freezer` fixture is automatically discovered by pytest. Users should inject it directly into their test functions or other fixtures without explicit import from `pytest_freezer`.
The `freezer` fixture is automatically available in your pytest tests. It is an instance of `freezegun.api.FrozenDateTimeFactory`, allowing direct use of its methods like `move_to()` or `freeze()` as a context manager. Time is frozen to the current moment by default when the fixture is injected, and can be manipulated thereafter.
from datetime import datetime
import time
def test_frozen_date(freezer):
# Time is frozen by default when the fixture is injected
now = datetime.now()
time.sleep(1)
later = datetime.now()
assert now == later
assert now.year == datetime.now().year # Verify object type
# You can also move time within the frozen period
freezer.move_to('2023-01-01 10:00:00')
assert datetime.now() == datetime(2023, 1, 1, 10, 0, 0)
# Use freezer as a context manager for temporary freezes
with freezer.freeze('2022-02-02'):
assert datetime.now().day == 2
Debug
Known issues
breakingThe explicit `freezer.start()` and `freezer.stop()` methods for managing time freezing were removed in `pytest-freezer` 0.4.6. This change aligns with `freezegun`'s recommended approach of using context managers or relying on the fixture's default behavior.fixRefactor tests to use `freezer` as a context manager (`with freezer.freeze('...')`) or rely on the fixture's default behavior of freezing time upon injection, and then use `freezer.move_to(...)` for changes within the frozen period. affects: <0.4.6
gotcha`pytest-freezer` requires `freezegun >= 1.1` since `pytest-freezer` 0.4.9. Earlier versions of `pytest-freezer` (e.g., 0.4.5) had a lower bound of `freezegun >= 1.0`. Using an older `freezegun` version may lead to unexpected behavior or compatibility issues.fixEnsure `freezegun` is updated to version `1.1` or higher. Check your project's dependency management files (e.g., `requirements.txt`, `pyproject.toml`) for `freezegun` version constraints.
affects: <0.4.9 with freezegun < 1.1
gotcha`pytest-freezer` is the actively maintained successor to the unmaintained `pytest-freezegun` plugin. `pytest-freezegun` has not been updated since 2020 and may cause deprecation warnings or compatibility issues with newer `pytest` or Python versions. `pytest-freezer` was transferred to the `pytest-dev` organization to provide a maintained alternative.fixMigrate from `pytest-freezegun` to `pytest-freezer` by uninstalling the old package and installing `pytest-freezer`. The fixture name (`freezer`) and basic usage patterns remain largely compatible, minimizing migration effort.
affects: All versions of `pytest-freezegun` (unmaintained)
deprecatedSupport and active testing for Python 3.6 and 3.7 were officially deprecated in `pytest-freezer` 0.4.9, aligning with their End-of-Life (EOL) status. While the `requires_python` metadata might still allow installation on these versions, continued compatibility is not guaranteed.fixUpgrade your Python environment to version 3.8 or newer to ensure full compatibility and continued support from `pytest-freezer` and the wider Python ecosystem.
affects: 0.4.9 and later when used with Python 3.6 or 3.7
Upgrade
Version history
0.4.9latest on PyPI · released Dec 12, 2024
Audit
Dependencies
pytestrequiredRequired for pytest plugin functionality.
freezegunrequiredCore dependency for time manipulation.