{"id":3774,"library":"pytest-freezegun","title":"pytest-freezegun","description":"pytest-freezegun is a pytest plugin that simplifies testing time-dependent code by integrating the `freezegun` library with pytest fixtures and marks. It allows you to freeze time during test execution using either a decorator or a dedicated fixture. The current version is 0.4.2, and it maintains a moderate release cadence, addressing compatibility and feature improvements.","status":"active","version":"0.4.2","language":"en","source_language":"en","source_url":"https://github.com/ktosiek/pytest-freezegun","tags":["pytest","testing","time","mocking","fixtures"],"install":[{"cmd":"pip install pytest-freezegun","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework pytest-freezegun extends.","package":"pytest","optional":false},{"reason":"The underlying library used for time freezing.","package":"freezegun","optional":false}],"imports":[{"note":"The 'freeze_time' mark is registered by the plugin and accessed via `pytest.mark`, not directly imported.","symbol":"pytest.mark.freeze_time","correct":"import pytest # accessed via pytest.mark"},{"note":"The 'freezer' fixture is automatically provided by the plugin.","symbol":"freezer (fixture)","correct":"def test_example(freezer):"}],"quickstart":{"code":"import datetime\nimport pytest\n\n@pytest.mark.freeze_time(\"2023-01-15 12:00:00\")\ndef test_frozen_time_decorator():\n    assert datetime.datetime.now() == datetime.datetime(2023, 1, 15, 12, 0, 0)\n\ndef test_frozen_time_fixture(freezer):\n    freezer.move_to(\"2024-02-29 10:30:00\")\n    assert datetime.datetime.now() == datetime.datetime(2024, 2, 29, 10, 30, 0)\n    freezer.tick(datetime.timedelta(hours=1))\n    assert datetime.datetime.now() == datetime.datetime(2024, 2, 29, 11, 30, 0)\n","lang":"python","description":"This quickstart demonstrates the two primary ways to freeze time with pytest-freezegun: using the `pytest.mark.freeze_time` decorator for a static time freeze on a test function, and using the `freezer` fixture to dynamically control time within a test, including advancing it."},"warnings":[{"fix":"Upgrade to Python 3.6+ to use pytest-freezegun 0.4.1+.","message":"Python 3.5 and older are no longer supported. Versions prior to 0.4.1 dropped support for Python < 3.5. Version 0.3.0 dropped support for Python 3.3.","severity":"breaking","affected_versions":"<0.4.1"},{"fix":"Upgrade to pytest-freezegun 0.4.1+ or explicitly register the mark in your `pytest.ini` using `markers = freeze_time`.","message":"The `freeze_time` mark was not automatically registered as a known mark in versions prior to 0.4.1. This could lead to pytest warnings about unknown marks.","severity":"gotcha","affected_versions":"<0.4.1"},{"fix":"Upgrade to pytest-freezegun 0.4.2+ which includes fixes for this interaction. Always ensure `freezer.move_to()` is called after `freeze_time` if dynamic adjustment is needed within a marked test.","message":"When both `@pytest.mark.freeze_time` and the `freezer` fixture are used in the same test or test scope, there were issues in older versions where `freeze_time` might not correctly freeze time in fixtures, or `freezer.move_to` might override unexpected values.","severity":"gotcha","affected_versions":"<0.4.2"},{"fix":"Upgrade to pytest-freezegun 0.4.1+ for reliable support with class-based tests.","message":"Support for class-based tests (e.g., using `@pytest.mark.freeze_time` on a test method within a class) was added in 0.4.1. Earlier versions might not apply the time freeze correctly to methods within test classes.","severity":"gotcha","affected_versions":"<0.4.1"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}