Skip to main content

Pytest plugin providing a fixture interface for spulec/freezegun

Project description

actions codecov pypi pyversions 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 Distribution

pytest_freezer-0.4.2.tar.gz (6.3 MB view details)

Uploaded Source

Built Distribution

pytest_freezer-0.4.2-py2.py3-none-any.whl (3.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest_freezer-0.4.2.tar.gz.

File metadata

  • Download URL: pytest_freezer-0.4.2.tar.gz
  • Upload date:
  • Size: 6.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.6

File hashes

Hashes for pytest_freezer-0.4.2.tar.gz
Algorithm Hash digest
SHA256 c7093e774eada220e255235c38645d86b76f781d9ac5b5b2f6d1e0368bcdcb7a
MD5 66d4c02c4461d3de3f9162a70d7f7bbe
BLAKE2b-256 c219cd63ff332556ca88962b8191fdaee0823e55ed2d812ac92000ae84384c24

See more details on using hashes here.

File details

Details for the file pytest_freezer-0.4.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_freezer-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 06dc3bedd215397e4ad6e724f3afeccc8f6603f5b0de340f8516d8d09e1f93a2
MD5 d84796e7de56b176bdf5b48a75c0790e
BLAKE2b-256 d3c8697f5d2561e84106f6c3ccb0dbaa1d8488f7c16b296e23d2587d309eddb2

See more details on using hashes here.

Supported by

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