{"id":4385,"library":"pytest-freezer","title":"Pytest Freezer","description":"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.","status":"active","version":"0.4.9","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-freezer","tags":["pytest","testing","time","mocking","freezegun"],"install":[{"cmd":"pip install pytest-freezer","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for pytest plugin functionality.","package":"pytest","version":">=3.6"},{"reason":"Core dependency for time manipulation.","package":"freezegun","version":">=1.1"}],"imports":[{"note":"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`.","wrong":"from pytest_freezer import freezer","symbol":"freezer","correct":"def test_my_feature(freezer):\n    # Use the freezer fixture directly"}],"quickstart":{"code":"from datetime import datetime\nimport time\n\ndef test_frozen_date(freezer):\n    # Time is frozen by default when the fixture is injected\n    now = datetime.now()\n    time.sleep(1)\n    later = datetime.now()\n    assert now == later\n    assert now.year == datetime.now().year # Verify object type\n\n    # You can also move time within the frozen period\n    freezer.move_to('2023-01-01 10:00:00')\n    assert datetime.now() == datetime(2023, 1, 1, 10, 0, 0)\n\n    # Use freezer as a context manager for temporary freezes\n    with freezer.freeze('2022-02-02'):\n        assert datetime.now().day == 2","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":"<0.4.6"},{"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.","message":"`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.","severity":"gotcha","affected_versions":"<0.4.9 with freezegun < 1.1"},{"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.","message":"`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.","severity":"gotcha","affected_versions":"All versions of `pytest-freezegun` (unmaintained)"},{"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.","message":"Support 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.","severity":"deprecated","affected_versions":"0.4.9 and later when used with Python 3.6 or 3.7"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}