Skip to content

Mess with the system clock at the vDSO level - useful for testing

Notifications You must be signed in to change notification settings

DavidVentura/py-tpom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Py-TPOM

This package hijacks the system's clock, which is useful for testing. It is similar to freezegun and py-libfaketime, the main differences are: it will override clock access for everything in the process (not just Python code) and it does not need files on disk (shared libraries or configuration files for faketime).

from py_timekeeper import Freezer
from datetime import datetime, timedelta

def test_time_changes():
    target = datetime(2012, 1, 14, 1, 2, 3)
    assert datetime.now() != target
    with Freezer(target):
        assert datetime.now() == target
    assert datetime.now() != target

def test_dst_change():
    start = datetime(2012, 1, 14, 1, 59, 59)
    after_dst = datetime(2012, 1, 14, 0, 59, 59)
    with Freezer(start) as ft:
        assert datetime.now() == start
        ft.tick(timedelta(hours=-1))
        assert datetime.now() != start
        assert datetime.now() == after_dst

About

Mess with the system clock at the vDSO level - useful for testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published