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.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
Built Distribution
File details
Details for the file freezefrog-0.3.tar.gz
.
File metadata
- Download URL: freezefrog-0.3.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68f3edc310da75ed0ad7aae6a758d5876f7f957a5c75437c5a74ca8a0e7810dd |
|
MD5 | 6b2d358d75088aa720413edf12154aa8 |
|
BLAKE2b-256 | 6ae1a8c96be6dc3fcea21c0218b9e452821510e427bc3046b749d00de7a4ac6c |
File details
Details for the file freezefrog-0.3-py2-none-any.whl
.
File metadata
- Download URL: freezefrog-0.3-py2-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee4523dc195dff1d3be2eceaaa2179caf75d2c6700f69d0aa078273eaeb037b5 |
|
MD5 | 3dd1a6e2b2d24f5bbbe9e9815b0f22fd |
|
BLAKE2b-256 | c62472bfad791129caf0fd620878456dfc2b68316cd13ee117cc567c25463f3c |