Skip to main content

Efficient datetime mocking in tests

Project description

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

FreezeFrog lets you efficiently mock datetimes in unit 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 unit 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 (if tz_delta is specified)

    • datetime.datetime.utcnow

    • time.time

Usage

Use the FreezeTime context manager to freeze the time. Pass the desired datetime object to the constructor. The constructor also takes the tick keyword argument (False by default), which makes the clock start ticking.

from freezefrog import FreezeTime
import datetime

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

freezefrog-0.3.2.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file freezefrog-0.3.2.tar.gz.

File metadata

  • Download URL: freezefrog-0.3.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for freezefrog-0.3.2.tar.gz
Algorithm Hash digest
SHA256 fd2a2dfc9c4d1e1c75b4c4b6e491258726d89866a5c4f970e4f1105f5e71a39b
MD5 ca7c3cff58fb117843ce62f0905ec257
BLAKE2b-256 9cb10bae9527fbf6b5b7343f09aa198cad69dc3fc9a778aa652b354366acdfdc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page