Skip to content

Guiforge/sleepfake

Repository files navigation

SleepFake Logo

PyPI version freezegun pytest fixture alpha

💤 SleepFake: Time Travel for Your Tests

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!

🚀 Features

  • Instantly skip over sleep calls in both sync and async code
  • Works with time.sleep and asyncio.sleep
  • Compatible with pytest and pytest-asyncio
  • Supports context manager and async context manager usage
  • No more slow tests—get results fast!

✨ Example Usage

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())

🧪 Why Use SleepFake?

  • 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?

📦 Installation

pip install sleepfake

🤝 Contributing

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.

About

Fake time.sleep/asyncio.sleep during tests.

Topics

Resources

License

Stars

Watchers

Forks