Skip to main content

Fake the time.sleep/asyncio.sleep function during tests.

Project description

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.

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

sleepfake-1.1.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sleepfake-1.1.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file sleepfake-1.1.2.tar.gz.

File metadata

  • Download URL: sleepfake-1.1.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sleepfake-1.1.2.tar.gz
Algorithm Hash digest
SHA256 3911475bfbe87ec6349ff4006dc030f69cea6ef755da0c80834c5a4cccc9d11d
MD5 43f68da391b3b6edc6d559bcf2723689
BLAKE2b-256 1ae638f7500d17ccbb2ae6404d65b29cbcc324bfa93ff1ca3623dfd1069b93d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleepfake-1.1.2.tar.gz:

Publisher: release.yml on Guiforge/sleepfake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sleepfake-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: sleepfake-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sleepfake-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 886411d93b413ef39976c84d4f1e110ed301ac94cdcec7ccb3d9e4715eaaa148
MD5 3fef7ea905d160c9ab8026dbfd862e91
BLAKE2b-256 6be9ca799ff2d6d127462f9e011de7dbe0488c48f5e1493a836f1438ab312679

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleepfake-1.1.2-py3-none-any.whl:

Publisher: release.yml on Guiforge/sleepfake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page