Pytest plugin providing a fixture interface for spulec/freezegun
Project description
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.3.tar.gz
(6.5 MB
view hashes)
Built Distribution
Close
Hashes for pytest_freezer-0.4.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92a2739f5190562b034bb4a4dd3d424505950fb844c4d1378de543dc7fe35bb5 |
|
MD5 | 66040bab500b3c3bcdb81efaaccbe487 |
|
BLAKE2b-256 | aa79139f56771f4aeafc9c078b7dac8648f10286b03ff35037b7bca4b0450351 |