Wrap tests with fixtures in freeze_time
- Freeze time in both the test and fixtures
- Access the freezer when you need it
$ pip install pytest-freezegun
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
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.
Distributed under the terms of the MIT license, "pytest-freezegun" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.