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.8.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file pytest_freezer-0.4.8.tar.gz
.
File metadata
- Download URL: pytest_freezer-0.4.8.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ee2f724b3ff3540523fa355958a22e6f4c1c819928b78a7a183ae4248ce6ee6 |
|
MD5 | b9c9051d17b55e4f9ea7b263ca22a18c |
|
BLAKE2b-256 | 69faa93d40dd50f712c276a5a15f9c075bee932cc4d28c376e60b4a35904976d |
File details
Details for the file pytest_freezer-0.4.8-py3-none-any.whl
.
File metadata
- Download URL: pytest_freezer-0.4.8-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 644ce7ddb8ba52b92a1df0a80a699bad2b93514c55cf92e9f2517b68ebe74814 |
|
MD5 | 99e4233b12a09713e3723ee381705212 |
|
BLAKE2b-256 | d84eba488639516a341810aeaeb4b32b70abb0923e53f7c4d14d673dc114d35a |