time-travel’s documentation

time-travel is a python library that allows users to write deterministic tests for time sensitive and I/O intensive code.

time-travel supports python 2.7, 3.5, 3.6, 3.7 and pypy on both Linux and Windows.

Quick start

Install

$ pip install time_travel

Usage

Here are two examples of how to use time-travel. See the full tutorial for more tips and tricks.

Mocking time-sensitive code

with TimeTravel():
    start = time.time()
    time.sleep(200)
    assert time.time() == start + 200

Mocking I/O code

with TimeTravel() as tt:
    sock = socket.socket()
    tt.add_future_event(time_from_now=2, sock, t.event_types.select.WRITE)

    now = time.time()
    assert select.select([], [sock], []) == ([], [sock], [])
    assert time.time() == now + 2