Skip to content

Pytest plugin providing a fixture interface for spulec/freezegun

License

Notifications You must be signed in to change notification settings

pytest-dev/pytest-freezer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Pytest plugin providing a fixture interface for spulec/freezegun

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages