Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pytest-freezer

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pytest-freezer

Pytest plugin providing a fixture interface for spulec/freezegun

  • 0.4.9
  • PyPI
  • Socket score

Maintainers
2

actions codecov pypi womm

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.

FAQs


Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc