Skip to content
Let your Python tests travel through time
Python Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
freezegun
tests
.gitignore
.travis.yml
LICENSE
Makefile
README.rst
requirements.txt
setup.cfg
setup.py

README.rst

FreezeGun: Let your Python tests travel through time

https://secure.travis-ci.org/spulec/freezegun.png?branch=master

FreezeGun is a library that allows you to travel in time with python by mocking the datetime module.

Installation

To install FreezeGun, simply:

$ pip install freezegun

Usage

Simple

from freezegun import freeze_time

freezer = freeze_time("2012-01-14")
freezer.start()
assert datetime.datetime.now() == datetime.datetime(2012, 01, 14)
freezer.stop()

Decorator

from freezegun import freeze_time

@freeze_time("2012-01-14")
def test():
    assert datetime.datetime.now() == datetime.datetime(2012, 01, 14)

Context Manager

from freezegun import freeze_time

def test():
    assert datetime.datetime.now() != datetime.datetime(2012, 01, 14)
    with freeze_time("2012-01-14"):
        assert datetime.datetime.now() == datetime.datetime(2012, 01, 14)
    assert datetime.datetime.now() != datetime.datetime(2012, 01, 14)
Something went wrong with that request. Please try again.