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.7.tar.gz
(3.0 kB
view details)
Built Distribution
File details
Details for the file pytest_freezer-0.4.7.tar.gz
.
File metadata
- Download URL: pytest_freezer-0.4.7.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9241ae5547110558f90394d8a51e216d1247a31f3c2518b1a70082f355f4864 |
|
MD5 | c6ce7dc8d39a66b7055e72df75c1bbb4 |
|
BLAKE2b-256 | 1a06a28ba59bad74f0f5b9146524c81acbc99599a4ac7c8b118f2b8773df26c5 |
File details
Details for the file pytest_freezer-0.4.7-py3-none-any.whl
.
File metadata
- Download URL: pytest_freezer-0.4.7-py3-none-any.whl
- Upload date:
- Size: 6.4 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 | e4cb3dcf10d16c15b445be4a710c85b56aaa8110f6ee6ee7b88ab85c462023b1 |
|
MD5 | 0f1400889606faf786e4a3d5406ac6f0 |
|
BLAKE2b-256 | c8f05f51803ee9ad3afa7cb79af29573fca35112b1e94c00d1d67453f53257bc |