-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[![actions](https://github.com/pytest-dev/pytest-freezer/actions/workflows/tests.yml/badge.svg)](https://github.com/pytest-dev/pytest-freezer/actions/workflows/tests.yml/) | ||
[![codecov](https://codecov.io/gh/pytest-dev/pytest-freezer/branch/main/graph/badge.svg)](https://codecov.io/gh/pytest-dev/pytest-freezer) | ||
[![pypi](https://img.shields.io/pypi/v/pytest-freezer.svg)](https://pypi.org/project/pytest-freezer) | ||
![womm](https://cdn.rawgit.com/nikku/works-on-my-machine/v0.2.0/badge.svg) | ||
|
||
# pytest-freezer | ||
|
||
[Pytest][1] plugin providing a fixture interface for [freezegun][2]. | ||
|
||
## Installation: | ||
|
||
``` bash | ||
$ 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][3] for the methods. | ||
|
||
Time is frozen by default when the fixture is injected: | ||
|
||
``` python | ||
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: | ||
|
||
``` python | ||
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][4] plugin. | ||
|
||
[1]: https://docs.pytest.org/ | ||
[2]: https://github.com/spulec/freezegun | ||
[3]: https://github.com/spulec/freezegun#usage | ||
[4]: https://github.com/ktosiek/pytest-freezegun |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,16 @@ build-backend = "flit_core.buildapi" | |
|
||
[project] | ||
name = "pytest_freezer" | ||
authors = [{name = "Wim Glenn", email = "[email protected]"}] | ||
authors = [{name = "Wim Jeantine-Glenn", email = "[email protected]"}] | ||
license = {file = "LICENSE"} | ||
classifiers = [ | ||
"License :: OSI Approved :: MIT License", | ||
"Framework :: Pytest", | ||
] | ||
version = "0.4.8" | ||
version = "0.4.9" | ||
dependencies = ["pytest >= 3.6", "freezegun >= 1.1"] | ||
requires-python = ">= 3.6" | ||
readme = "README.rst" | ||
readme = "README.md" | ||
description = "Pytest plugin providing a fixture interface for spulec/freezegun" | ||
|
||
[project.urls] | ||
|