Skip to main content

Pytest plugin providing a fixture interface for spulec/freezegun

Project description

actions codecov pypi womm

pytest-freezer

Pytest plugin providing a fixture interface for freezegun.

Installation:

$ 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 for the methods.

Time is frozen by default when the fixture is injected:

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:

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 plugin.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pytest_freezer-0.4.5-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_freezer-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: pytest_freezer-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pytest_freezer-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d51fa35d35279659b39d0e868f7c49463c499fae564e14bcfac1d60ed5b6fbf5
MD5 c3b8842735e6b0831f4a05e2146a0935
BLAKE2b-256 e549a382310348d7682f7ff92aa38155cc549abf2a72d7ee86a5c99ffe469ef4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page