pax_global_header00006660000000000000000000000064147265220360014521gustar00rootroot0000000000000052 comment=d6fcf3856b8fd20c11a172bb329c432d708d5e80 pytest-freezer-0.4.9/000077500000000000000000000000001472652203600145235ustar00rootroot00000000000000pytest-freezer-0.4.9/.github/000077500000000000000000000000001472652203600160635ustar00rootroot00000000000000pytest-freezer-0.4.9/.github/workflows/000077500000000000000000000000001472652203600201205ustar00rootroot00000000000000pytest-freezer-0.4.9/.github/workflows/tests.yml000066400000000000000000000023321472652203600220050ustar00rootroot00000000000000name: tests on: push: branches: [main] pull_request: branches: [main] schedule: - cron: "0 0 * * 0" workflow_dispatch: jobs: tests: name: Python ${{ matrix.python-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - ubuntu-latest - macos-latest - windows-latest python-version: - "3.8" - "3.9" - "3.10" - "3.11" - "3.12" steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install run: pip install coverage . - name: Run tests for ${{ matrix.python-version }} on ${{ matrix.os }} run: coverage run --source=pytest_freezer -m pytest && coverage report -m - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: fail_ci_if_error: false token: ${{ secrets.CODECOV_TOKEN }} check-package: name: Build & inspect our package. runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: hynek/build-and-inspect-python-package@v2 pytest-freezer-0.4.9/LICENSE000066400000000000000000000020521472652203600155270ustar00rootroot00000000000000MIT License Copyright (c) 2022 wim glenn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pytest-freezer-0.4.9/README.md000066400000000000000000000031521472652203600160030ustar00rootroot00000000000000[![actions](https://github.com/pytest-dev/pytest-freezer/actions/workflows/tests.yml/badge.svg)](https://github.com/pytest-dev/pytest-freezer/actions/workflows/tests.yml/) [![codecov](https://codecov.io/gh/pytest-dev/pytest-freezer/branch/main/graph/badge.svg)](https://codecov.io/gh/pytest-dev/pytest-freezer) [![pypi](https://img.shields.io/pypi/v/pytest-freezer.svg)](https://pypi.org/project/pytest-freezer) ![womm](https://cdn.rawgit.com/nikku/works-on-my-machine/v0.2.0/badge.svg) # pytest-freezer [Pytest][1] plugin providing a fixture interface for [freezegun][2]. ## Installation: ``` bash $ python -m pip install pytest-freezer ``` ## Usage: The fixture name is `freezer`. It is a `freezegun.api.FrozenDateTimeFactory` instance, so refer to upstream freezegun [usage][3] for the methods. Time is frozen by default when the fixture is injected: ``` python def test_frozen_date(freezer): now = datetime.now() time.sleep(1) later = datetime.now() assert now == later ``` Time can be controlled within a test by using methods on the fixture: ``` python def test_freezer_methods(freezer): freezer.move_to("2022-10-17") assert datetime.now() == datetime(2022, 10, 17) freezer.tick() assert datetime.now() == datetime(2022, 10, 17, 0, 0, 1) freezer.tick(delta=12) assert datetime.now() == datetime(2022, 10, 17, 0, 0, 13) ``` ## Acknowledgements: Credit to Tomasz Kontusz for the original [pytest-freezegun][4] plugin. [1]: https://docs.pytest.org/ [2]: https://github.com/spulec/freezegun [3]: https://github.com/spulec/freezegun#usage [4]: https://github.com/ktosiek/pytest-freezegun pytest-freezer-0.4.9/pyproject.toml000066400000000000000000000012551472652203600174420ustar00rootroot00000000000000[build-system] requires = ["flit_core >=3.2,<4"] build-backend = "flit_core.buildapi" [project] name = "pytest_freezer" authors = [{name = "Wim Jeantine-Glenn", email = "hey@wimglenn.com"}] license = {file = "LICENSE"} classifiers = [ "License :: OSI Approved :: MIT License", "Framework :: Pytest", ] version = "0.4.9" dependencies = ["pytest >= 3.6", "freezegun >= 1.1"] requires-python = ">= 3.6" readme = "README.md" description = "Pytest plugin providing a fixture interface for spulec/freezegun" [project.urls] Homepage = "https://github.com/pytest-dev/pytest-freezer" [project.entry-points.pytest11] freezer = "pytest_freezer" [tool.flit.sdist] include = ["tests/"] pytest-freezer-0.4.9/pytest_freezer.py000066400000000000000000000013571472652203600201550ustar00rootroot00000000000000import freezegun import pytest freezegun.configure(extend_ignore_list=["_pytest.terminal", "_pytest.runner"]) @pytest.fixture def freezer(request): """Freeze time by mocking the datetime module""" marker = request.node.get_closest_marker("freeze_time") args = getattr(marker, "args", ()) kwargs = getattr(marker, "kwargs", {}) with freezegun.freeze_time(*args, **kwargs) as frozen_datetime_factory: yield frozen_datetime_factory def pytest_collection_modifyitems(items): for item in items: if item.get_closest_marker("freeze_time"): item.fixturenames.insert(0, "freezer") def pytest_configure(config): config.addinivalue_line("markers", "freeze_time(...): use freezegun to freeze time") pytest-freezer-0.4.9/tests/000077500000000000000000000000001472652203600156655ustar00rootroot00000000000000pytest-freezer-0.4.9/tests/conftest.py000066400000000000000000000000361472652203600200630ustar00rootroot00000000000000pytest_plugins = ["pytester"] pytest-freezer-0.4.9/tests/test_plugin.py000066400000000000000000000053111472652203600205740ustar00rootroot00000000000000def test_freezer_move_to_method(pytester): pytester.makepyfile( """ from datetime import datetime def test_freezer_move_to_method(freezer): freezer.move_to("2021-01-01") assert datetime.now().year == 2021 freezer.move_to("2022-01-01") assert datetime.now().year == 2022 """ ) pytester.runpytest().assert_outcomes(passed=1) def test_mark_decorator(pytester): pytester.makepyfile( """ import pytest from datetime import datetime @pytest.mark.freeze_time("2022-10-17T12:34:56") def test_mark_decorator(): assert datetime.now().isoformat() == "2022-10-17T12:34:56" """ ) pytester.runpytest().assert_outcomes(passed=1) def test_frozen_by_default_with_fixture(pytester): pytester.makepyfile( """ import time from datetime import datetime def test_frozen_by_default_with_fixture(freezer): dt1 = datetime.now() time.sleep(0.01) dt2 = datetime.now() assert dt1 == dt2 """ ) pytester.runpytest().assert_outcomes(passed=1) def test_not_frozen_with_no_fixture(pytester): pytester.makepyfile( """ import time from datetime import datetime def test_not_frozen_with_no_fixture(): dt1 = datetime.now() time.sleep(0.01) dt2 = datetime.now() assert dt1 < dt2 """ ) pytester.runpytest().assert_outcomes(passed=1) def test_tick_method(pytester): pytester.makepyfile( """ from datetime import datetime def test_tick_method(freezer): freezer.move_to("2022-10-17") assert datetime.now() == datetime(2022, 10, 17) freezer.tick() assert datetime.now() == datetime(2022, 10, 17, 0, 0, 1) freezer.tick(delta=12) assert datetime.now() == datetime(2022, 10, 17, 0, 0, 13) """ ) pytester.runpytest().assert_outcomes(passed=1) def test_durations(pytester): pytester.makepyfile( """ def test_durations(freezer): freezer.move_to('2000-01-01') """ ) result = pytester.runpytest("--durations=3", "-vv") durations = {} for line in result.outlines: if "test_durations.py::test_durations" not in line: continue for stage in "setup", "call", "teardown": if stage in line: duration = line.split()[0] durations[stage] = float(duration[:-1]) assert 0 <= durations["setup"] <= 1 assert 0 <= durations["call"] <= 1 assert 0 <= durations["teardown"] <= 1