Ever wish your tests could skip the wait? SleepFake lets you fake time.sleep
and asyncio.sleep
so your tests run at lightning speed—no more wasting time waiting for the clock!
- Instantly skip over
sleep
calls in both sync and async code - Works with
time.sleep
andasyncio.sleep
- Compatible with pytest and pytest-asyncio
- Supports context manager and async context manager usage
- No more slow tests—get results fast!
from sleepfake import SleepFake
import time
import asyncio
# Synchronous example
with SleepFake():
start = time.time()
time.sleep(10) # Instantly skipped!
end = time.time()
print(f"Elapsed: {end - start:.2f}s") # Elapsed: 10.00s
# Asynchronous example
async def main():
async with SleepFake():
start = asyncio.get_event_loop().time()
await asyncio.sleep(5) # Instantly skipped!
end = asyncio.get_event_loop().time()
print(f"Elapsed: {end - start:.2f}s") # Elapsed: 5.00s
asyncio.run(main())
- Speed up your test suite: No more real waiting!
- Test time-based logic: Simulate long waits, retries, and timeouts instantly.
- Fun to use: Who doesn't love time travel?
pip install sleepfake
PRs and issues welcome! Help make testing even more fun.
Made with ❤️ and a dash of impatience.
Note: SleepFake uses freezegun under the hood for time manipulation magic.