Skip to main content

Are you tired of unpredictable time values messing with your testing? Enter Tyminator, a testing toolkit that terminates uncertainty and boosts the reliability of your tests.

Just like how database fixtures provide predictable data sets, Tyminator brings that same level of predictability to time. Tyminator enables precise control over time-related operations in testing scenarios by seamlessly replacing the built-in Python time functions.

Importance of Predictable Time Test Fixtures

Test fixtures are the guardians of correctness and stability in software applications, setting the stage for tests with data, dependencies, and environment configurations. But when it comes to time-sensitive operations like scheduling events or handling timeouts, relying on the actual passage of time introduces non-deterministic behavior, making it challenging to reproduce and debug issues consistently.

By controlling time, developers can isolate specific scenarios, simulate time-based events, and test edge cases that would otherwise be difficult to replicate reliably. This control allows for comprehensive testing of time-sensitive functionality, including handling time zones, time-based calculations, and scheduling logic.

Key features

The library offers a range of features and methods to manipulate time, schedule events, calculate durations, and track elapsed time, ensuring accurate and repeatable test results.

  • Patching Time Functions: Tyminator seamlessly replaces the built-in Python time functions with a fake clock implementation. This allows tests to control and manipulate time-related operations without affecting or being affected by the actual system time.

  • Fine-Grained Time Manipulation: Test fixtures can move time forward in controlled increments, making it possible to simulate various time-based scenarios accurately. This enables comprehensive testing of time-dependent code paths.

  • Predictable Timestamp Generation: Test fixtures can generate consistent and predictable timestamps, eliminating non-deterministic behavior associated with real-time values. This ensures reliable test results and simplifies debugging.

  • Time Zone Support: Supports simulating alternate local time zones, allowing tests to ensure that time-dependent code handles regional changes correctly.

  • Events: Ability to specify specific times when for triggering events, helping to simulate specific sequences of normally unpredictable sequences in asynchronous code paths.

Installation

Tyminator is available as the Python tyminator package.

For example, to install using pip:

$ pip install tyminator

Usage with unittests

import time
import unittest
from datetime import datetime, timezone
from datetime import timedelta

from tyminator.clock import Clock
from tyminator.clock import installed

EPOCH = datetime(2016, 8, 29, 18, 18)
EASTERN_TIME = timedelta(hours=-5)

class MyTimeTest(unittest.TestCase):
    def setUp(self):
        self.clock = Clock(EPOCH, local_tz=timezone(EASTERN_TIME))

    def test_example(self):
        with installed(self.clock):
            now1 = datetime.fromtimestamp(time.time())
            assert now1 == EPOCH

            now2 = datetime.fromtimestamp(time.time())
            assert now2 == EPOCH + self.clock.step

            naive_utc = EPOCH + self.clock.step * 2 - EASTERN_TIME
            assert self.clock.current_utc_datetime == naive_utc.replace(tzinfo=timezone.utc)

Metadata

Release files for tyminator 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tyminator 1.0.1
File Size Uploaded Provenance Actions
tyminator-1.0.1.tar.gz 10.3 kB With provenance Details for tyminator-1.0.1.tar.gz

Release files / tyminator-1.0.1.tar.gz

Download URL tyminator-1.0.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
272ab64a1f0c0d6260676e8fd6d68df6bbff52355a688f5863891adbaef433ae
BLAKE2b-256 checksum
How to use checksums
ae1b51a14abd581d7e61a016c4a34d504db4df014af4cfbf2c699875a69c3eb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 13, 2025.

Transparency log

Security for tyminator 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 1 file in this release has been uploaded with provenance metadata.

Attestation for tyminator-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 13, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page