temporal-python-testing

Test Temporal workflows with pytest, time-skipping, and mocking strategies. Covers unit testing, integration testing, replay testing, and local development setup. Use when implementing Temporal workflow tests or debugging test failures.

Author

Install

Hot:7

Download and extract to your skills directory

Copy command and send to OpenClaw for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-temporal-python-testing&locale=en&source=copy

Temporal Python Testing

Use pytest and time-skipping to quickly test Temporal workflows, covering a complete testing strategy including unit tests, integration tests, replay tests, and local development environment setup.

Applicable Scenarios

  • Unit Testing Workflows — Use the time-skipping feature of WorkflowEnvironment to run a workflow that would normally take one month in just a few seconds, quickly verifying that the workflow logic is correct.
  • Integration Testing and Mocking — Mock external activity dependencies to isolate workflow business logic, avoiding calls to real external services and improving test stability and execution speed.
  • Production Validation and Replay Testing — Before deployment, replay tests using history from the production environment to verify determinism after workflow code changes, preventing runtime errors caused by non-deterministic behavior.
  • Core Features

  • Time-Skipping Fast Testing — Leverage WorkflowEnvironment to automatically jump time, enabling workflows containing long waits (e.g., sleep, timers) to complete tests in milliseconds while preserving accurate time-related logic.
  • Activity Mocking Strategy — Provide a complete set of patterns such as activity mocking, error injection, and multi-activity collaboration testing, helping developers isolate external dependencies and focus on testing the workflow’s core logic.
  • Full Testing Toolchain — Includes local Temporal server Docker configuration, pytest async fixtures, coverage tool integration, and CI/CD pipeline configuration, supporting a target of ≥80% test coverage.
  • Common Questions

    How can time-skipping make a one-month workflow test finish in seconds?

    In time-skipping mode, WorkflowEnvironment automatically skips all waiting times in the workflow (e.g., await asyncio.sleep(30 days)), executing only the actual business logic. When the workflow needs to wait for a certain time point, the test environment immediately advances time to that point instead of waiting in real time. This allows the original one-month workflow to complete within seconds while maintaining deterministic time logic.

    When should replay testing be used?

    Replay testing is mainly used for scenarios such as verifying before deployment that workflow code changes won’t break determinism, validating compatibility after upgrading the Temporal SDK version, and reproducing non-deterministic errors from the production environment. Replay tests re-execute the workflow using real Event History from production. If the new code produces a different decision path, the test fails immediately, helping you catch issues before deployment.

    How to achieve the recommended 80% test coverage?

    Adopt a layered testing strategy: use unit tests to cover core workflow logic branches (time-skipping makes these tests very fast), use integration tests to cover activity calls and error-handling paths, and use replay tests to cover all production workflow versions. Configure pytest-cov to check coverage regularly. Set coverage targets for critical business logic to ≥80%; for complex workflows, higher coverage is recommended.