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.
Add this skill
npx mdskills install sickn33/temporal-python-testingExcellent progressive disclosure design with clear testing philosophy and resource organization
1---2name: temporal-python-testing3description: 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.4---56# Temporal Python Testing Strategies78Comprehensive testing approaches for Temporal workflows using pytest, progressive disclosure resources for specific testing scenarios.910## Do not use this skill when1112- The task is unrelated to temporal python testing strategies13- You need a different domain or tool outside this scope1415## Instructions1617- Clarify goals, constraints, and required inputs.18- Apply relevant best practices and validate outcomes.19- Provide actionable steps and verification.20- If detailed examples are required, open `resources/implementation-playbook.md`.2122## Use this skill when2324- **Unit testing workflows** - Fast tests with time-skipping25- **Integration testing** - Workflows with mocked activities26- **Replay testing** - Validate determinism against production histories27- **Local development** - Set up Temporal server and pytest28- **CI/CD integration** - Automated testing pipelines29- **Coverage strategies** - Achieve ≥80% test coverage3031## Testing Philosophy3233**Recommended Approach** (Source: docs.temporal.io/develop/python/testing-suite):3435- Write majority as integration tests36- Use pytest with async fixtures37- Time-skipping enables fast feedback (month-long workflows → seconds)38- Mock activities to isolate workflow logic39- Validate determinism with replay testing4041**Three Test Types**:42431. **Unit**: Workflows with time-skipping, activities with ActivityEnvironment442. **Integration**: Workers with mocked activities453. **End-to-end**: Full Temporal server with real activities (use sparingly)4647## Available Resources4849This skill provides detailed guidance through progressive disclosure. Load specific resources based on your testing needs:5051### Unit Testing Resources5253**File**: `resources/unit-testing.md`54**When to load**: Testing individual workflows or activities in isolation55**Contains**:5657- WorkflowEnvironment with time-skipping58- ActivityEnvironment for activity testing59- Fast execution of long-running workflows60- Manual time advancement patterns61- pytest fixtures and patterns6263### Integration Testing Resources6465**File**: `resources/integration-testing.md`66**When to load**: Testing workflows with mocked external dependencies67**Contains**:6869- Activity mocking strategies70- Error injection patterns71- Multi-activity workflow testing72- Signal and query testing73- Coverage strategies7475### Replay Testing Resources7677**File**: `resources/replay-testing.md`78**When to load**: Validating determinism or deploying workflow changes79**Contains**:8081- Determinism validation82- Production history replay83- CI/CD integration patterns84- Version compatibility testing8586### Local Development Resources8788**File**: `resources/local-setup.md`89**When to load**: Setting up development environment90**Contains**:9192- Docker Compose configuration93- pytest setup and configuration94- Coverage tool integration95- Development workflow9697## Quick Start Guide9899### Basic Workflow Test100101```python102import pytest103from temporalio.testing import WorkflowEnvironment104from temporalio.worker import Worker105106@pytest.fixture107async def workflow_env():108 env = await WorkflowEnvironment.start_time_skipping()109 yield env110 await env.shutdown()111112@pytest.mark.asyncio113async def test_workflow(workflow_env):114 async with Worker(115 workflow_env.client,116 task_queue="test-queue",117 workflows=[YourWorkflow],118 activities=[your_activity],119 ):120 result = await workflow_env.client.execute_workflow(121 YourWorkflow.run,122 args,123 id="test-wf-id",124 task_queue="test-queue",125 )126 assert result == expected127```128129### Basic Activity Test130131```python132from temporalio.testing import ActivityEnvironment133134async def test_activity():135 env = ActivityEnvironment()136 result = await env.run(your_activity, "test-input")137 assert result == expected_output138```139140## Coverage Targets141142**Recommended Coverage** (Source: docs.temporal.io best practices):143144- **Workflows**: ≥80% logic coverage145- **Activities**: ≥80% logic coverage146- **Integration**: Critical paths with mocked activities147- **Replay**: All workflow versions before deployment148149## Key Testing Principles1501511. **Time-Skipping** - Month-long workflows test in seconds1522. **Mock Activities** - Isolate workflow logic from external dependencies1533. **Replay Testing** - Validate determinism before deployment1544. **High Coverage** - ≥80% target for production workflows1555. **Fast Feedback** - Unit tests run in milliseconds156157## How to Use Resources158159**Load specific resource when needed**:160161- "Show me unit testing patterns" → Load `resources/unit-testing.md`162- "How do I mock activities?" → Load `resources/integration-testing.md`163- "Setup local Temporal server" → Load `resources/local-setup.md`164- "Validate determinism" → Load `resources/replay-testing.md`165166## Additional References167168- Python SDK Testing: docs.temporal.io/develop/python/testing-suite169- Testing Patterns: github.com/temporalio/temporal/blob/main/docs/development/testing.md170- Python Samples: github.com/temporalio/samples-python171
Full transparency — inspect the skill content before installing.