Skip to main content
https://circleci.com/gh/closeio/freezefrog/tree/master.svg?style=svg&circle-token=010565a97316df8a248f0f32d584357021a3873b

FreezeFrog lets you mock datetimes in tests.

(Interested in working on projects like this? Close.io is looking for great engineers to join our team.)

Why FreezeFrog?

FreezeFrog is a Python library that lets you mock datetimes in tests. Its goal is to be simple and fast.

  • In comparison to certain other time freezing libraries, FreezeFrog doesn’t loop through all imported modules, making it fast even for larger projects.

  • FreezeFrog currently supports mocking the following basic methods:

    • datetime.datetime.now

    • datetime.datetime.utcnow

    • time.time

  • FreezeFrog supports both datetime and pytz timezone objects.

Usage

Use the FreezeTime context manager to freeze the time. Pass the desired datetime object to the constructor, and the timezone to mock the system’s timezone (defaults to datetime.timzone.utc). The constructor also takes the fold argument (0 by default), which defines whether an ambiguous time refers to its first or second appearance, and the tick argument (False by default), which makes the clock start ticking.

import datetime

from freezefrog import FreezeTime

with FreezeTime(datetime.datetime(2014, 1, 1)):
    # The clock is frozen.
    # Always prints 2014-01-01 00:00:00
    print(datetime.datetime.utcnow())

with FreezeTime(datetime.datetime(2014, 1, 1), tick=True):
    # The clock starts ticking immediately.
    # Example output: 2014-01-01 00:00:00.000005
    print(datetime.datetime.utcnow())

Release files for freezefrog 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for freezefrog 0.4.1
File Size Uploaded
freezefrog-0.4.1.tar.gz 3.8 kB Details

Release files / freezefrog-0.4.1.tar.gz

Download URL freezefrog-0.4.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b35f6eb17bd79351d74f8536458090a79fde4d5af8de067816c1653b026fb752
BLAKE2b-256 checksum
How to use checksums
3f97f82c0c65ffdee26955c0ed11b190d32c90a49a0bc999d97511db766f82c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

2 release files

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page