Efficient datetime mocking in tests
Project description
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.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
File details
Details for the file freezefrog-0.1.tar.gz
.
File metadata
- Download URL: freezefrog-0.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d2d11379de42cd7e60a5bf6982180ba4b27af72b291327e5c9fdd42e54b8431 |
|
MD5 | 71d6a5e338b08c9e0694e738ba1fc02c |
|
BLAKE2b-256 | 97c4dfc684aede3946599a6542dd175c0b92229d11439e918b11426240ce701f |