Wrap tests with fixtures in freeze_time
Project description
Wrap tests with fixtures in freeze_time
Features
Freeze time in both the test and fixtures
Access the freezer when you need it
Installation
You can install “pytest-freezegun” via pip from PyPI:
$ pip install pytest-freezegun
Usage
All the features can be seen in this example:
@pytest.fixture
def current_date():
return datetime.now().date()
@pytest.mark.freeze_time('2017-05-21')
def test_current_date(current_date):
assert current_date == date(2017, 5, 21)
@pytest.mark.freeze_time
def test_changing_date(current_date, freezer):
freezer.move_to('2017-05-20')
assert current_date == date(2017, 5, 20)
freezer.move_to('2017-05-21')
assert current_date == date(2017, 5, 21)
def test_not_using_marker(freezer):
now = datetime.now()
time.sleep(1)
later = datetime.now()
assert now == later
Contributing
Contributions are very welcome. Tests can be run with tox. You can later check coverage with coverage combine && coverage html. Please try to keep coverage at least the same before you submit a pull request.
License
Distributed under the terms of the MIT license, “pytest-freezegun” is free and open source software
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
This Pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for pytest_freezegun-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88bb8c2a0b3a9623dd2a565693786d6a0f87aaf929dfca2b1680b5d84abcde71 |
|
MD5 | b796f317aac610e8885c4db8cc1d4001 |
|
BLAKE2b-256 | 688cc65f31ac0059ad939903131142ae64cbf47ae12756a78e851831471394e3 |