
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
pytest-freezegun
Advanced tools
.. image:: https://img.shields.io/pypi/v/pytest-freezegun.svg :target: https://pypi.python.org/pypi/pytest-freezegun/
.. image:: https://travis-ci.org/ktosiek/pytest-freezegun.svg?branch=master :target: https://travis-ci.org/ktosiek/pytest-freezegun :alt: See Build Status on Travis CI
.. image:: https://ci.appveyor.com/api/projects/status/github/ktosiek/pytest-freezegun?branch=master&svg=true :target: https://ci.appveyor.com/project/ktosiek/pytest-freezegun/branch/master :alt: See Build Status on AppVeyor
Wrap tests with fixtures in freeze_time
You can install "pytest-freezegun" via pip_ from PyPI_::
$ pip install pytest-freezegun
Freeze time by using the freezer fixture::
def test_frozen_date(freezer):
now = datetime.now()
time.sleep(1)
later = datetime.now()
assert now == later
This can then be used to move time::
def test_moving_date(freezer):
now = datetime.now()
freezer.move_to('2017-05-20')
later = datetime.now()
assert now != later
You can also pass arguments to freezegun by using the freeze_time mark::
@pytest.mark.freeze_time('2017-05-21')
def test_current_date():
assert date.today() == date(2017, 5, 21)
The freezer fixture and freeze_time mark can be used together,
and they work with other fixtures::
@pytest.fixture
def current_date():
return date.today()
@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)
They can also be used in class-based tests::
class TestDate:
@pytest.mark.freeze_time
def test_changing_date(self, 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)
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.
This Pytest_ plugin was generated with Cookiecutter_ along with @hackebrot's Cookiecutter-pytest-plugin template.
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _@hackebrot: https://github.com/hackebrot
.. _MIT: http://opensource.org/licenses/MIT
.. _cookiecutter-pytest-plugin: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _file an issue: https://github.com/ktosiek/pytest-freezegun/issues
.. _pytest: https://github.com/pytest-dev/pytest
.. _tox: https://tox.readthedocs.io/en/latest/
.. _pip: https://pypi.python.org/pypi/pip/
.. _PyPI: https://pypi.python.org/pypi
FAQs
Wrap tests with fixtures in freeze_time
We found that pytest-freezegun demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.