Registry / testing / pytest-freezer

pytest-freezer

JSON →
library0.4.9pypypi✓ verified 25d ago

Pytest-freezer is a pytest plugin that provides a fixture interface for the `freezegun` library, allowing developers to easily freeze and manipulate time during tests. It ensures consistent testing of time-based functionality, such as scheduling, expiry mechanisms, and historical data retrieval. Maintained by the `pytest-dev` organization, the current version is 0.4.9 and is actively developed.

pip install pytest-freezer
INSTALL
IMPORT
SIG · PYTEST-FREEZER
P
pytest-freezer
testingpythonv0.4.9
Install
2.9s avg
Import
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 32.1MB
glibc
py 3.103.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.
fix
Refactor 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.
fix
Ensure `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.
fix
Migrate 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.
fix
Upgrade 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.
Agent activity
9 hits · last 30 days
node
6
Bingbot
1
Resources
pytest-freezer — pip install pytest-freezer · libregistry