Temporal Python Testing
Skill files5 files

resources/

SKILL.md159 lines
1
---
2
name: temporal-python-testing
3
description: 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
---
5
6
# Temporal Python Testing Strategies
7
8
Comprehensive testing approaches for Temporal workflows using pytest, progressive disclosure resources for specific testing scenarios.
9
10
## When to Use This Skill
11
12
- **Unit testing workflows** - Fast tests with time-skipping
13
- **Integration testing** - Workflows with mocked activities
14
- **Replay testing** - Validate determinism against production histories
15
- **Local development** - Set up Temporal server and pytest
16
- **CI/CD integration** - Automated testing pipelines
17
- **Coverage strategies** - Achieve ≥80% test coverage
18
19
## Testing Philosophy
20
21
**Recommended Approach** (Source: docs.temporal.io/develop/python/testing-suite):
22
23
- Write majority as integration tests
24
- Use pytest with async fixtures
25
- Time-skipping enables fast feedback (month-long workflows → seconds)
26
- Mock activities to isolate workflow logic
27
- Validate determinism with replay testing
28
29
**Three Test Types**:
30
31
1. **Unit**: Workflows with time-skipping, activities with ActivityEnvironment
32
2. **Integration**: Workers with mocked activities
33
3. **End-to-end**: Full Temporal server with real activities (use sparingly)
34
35
## Available Resources
36
37
This skill provides detailed guidance through progressive disclosure. Load specific resources based on your testing needs:
38
39
### Unit Testing Resources
40
41
**File**: `resources/unit-testing.md`
42
**When to load**: Testing individual workflows or activities in isolation
43
**Contains**:
44
45
- WorkflowEnvironment with time-skipping
46
- ActivityEnvironment for activity testing
47
- Fast execution of long-running workflows
48
- Manual time advancement patterns
49
- pytest fixtures and patterns
50
51
### Integration Testing Resources
52
53
**File**: `resources/integration-testing.md`
54
**When to load**: Testing workflows with mocked external dependencies
55
**Contains**:
56
57
- Activity mocking strategies
58
- Error injection patterns
59
- Multi-activity workflow testing
60
- Signal and query testing
61
- Coverage strategies
62
63
### Replay Testing Resources
64
65
**File**: `resources/replay-testing.md`
66
**When to load**: Validating determinism or deploying workflow changes
67
**Contains**:
68
69
- Determinism validation
70
- Production history replay
71
- CI/CD integration patterns
72
- Version compatibility testing
73
74
### Local Development Resources
75
76
**File**: `resources/local-setup.md`
77
**When to load**: Setting up development environment
78
**Contains**:
79
80
- Docker Compose configuration
81
- pytest setup and configuration
82
- Coverage tool integration
83
- Development workflow
84
85
## Quick Start Guide
86
87
### Basic Workflow Test
88
89
```python
90
import pytest
91
from temporalio.testing import WorkflowEnvironment
92
from temporalio.worker import Worker
93
94
@pytest.fixture
95
async def workflow_env():
96
env = await WorkflowEnvironment.start_time_skipping()
97
yield env
98
await env.shutdown()
99
100
@pytest.mark.asyncio
101
async def test_workflow(workflow_env):
102
async with Worker(
103
workflow_env.client,
104
task_queue="test-queue",
105
workflows=[YourWorkflow],
106
activities=[your_activity],
107
):
108
result = await workflow_env.client.execute_workflow(
109
YourWorkflow.run,
110
args,
111
id="test-wf-id",
112
task_queue="test-queue",
113
)
114
assert result == expected
115
```
116
117
### Basic Activity Test
118
119
```python
120
from temporalio.testing import ActivityEnvironment
121
122
async def test_activity():
123
env = ActivityEnvironment()
124
result = await env.run(your_activity, "test-input")
125
assert result == expected_output
126
```
127
128
## Coverage Targets
129
130
**Recommended Coverage** (Source: docs.temporal.io best practices):
131
132
- **Workflows**: ≥80% logic coverage
133
- **Activities**: ≥80% logic coverage
134
- **Integration**: Critical paths with mocked activities
135
- **Replay**: All workflow versions before deployment
136
137
## Key Testing Principles
138
139
1. **Time-Skipping** - Month-long workflows test in seconds
140
2. **Mock Activities** - Isolate workflow logic from external dependencies
141
3. **Replay Testing** - Validate determinism before deployment
142
4. **High Coverage** - ≥80% target for production workflows
143
5. **Fast Feedback** - Unit tests run in milliseconds
144
145
## How to Use Resources
146
147
**Load specific resource when needed**:
148
149
- "Show me unit testing patterns" → Load `resources/unit-testing.md`
150
- "How do I mock activities?" → Load `resources/integration-testing.md`
151
- "Setup local Temporal server" → Load `resources/local-setup.md`
152
- "Validate determinism" → Load `resources/replay-testing.md`
153
154
## Additional References
155
156
- Python SDK Testing: docs.temporal.io/develop/python/testing-suite
157
- Testing Patterns: github.com/temporalio/temporal/blob/main/docs/development/testing.md
158
- Python Samples: github.com/temporalio/samples-python
159

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 11,962 prompts

More by @OpenSourceBuffGuy

See all
Ancient Civilization Miniature Diorama prompt image

Ancient Civilization Miniature Diorama

Draws a realistic miniature diorama of an ancient civilization's monuments under construction, set on blueprints atop a wooden drafting table.

image-prompt, gpt-image, miniature, photorealistic, architecture, history, blueprint, 3d-render, cinematic, natural-light, vertical-format, placeholders, long-form, construction, still-life, bokeh, architectural-rendering, for-artists, concept-art, fantasy-world

Error Handling Patterns prompt image

Error Handling Patterns

Teaches an AI agent resilient error handling across languages: exceptions versus Result types, propagation, retries, circuit breakers and graceful degradation.

agent-skill, best-practices, coding, backend, api, debugging, design-patterns, distributed-systems, clean-code, code, code-generation, software-architecture, troubleshooting, for-developers, advanced, long-form, cheat-sheet, guardrails, observability, refactoring, site-reliability, microservices, error-handling

Riot Ink Screenprint Collage prompt image

Riot Ink Screenprint Collage

Defines a reusable JSON style for punk-zine screenprint posters: a thresholded photo hero, black, yellow and red spot inks, a huge headline band and painted marks.

image-prompt, json-prompt, placeholders, poster, collage, printmaking, typography, structured-output, style-reference, limited-palette, vibrant-colors, black-and-white, film-grain, text-rendering, vertical-format, long-form, advanced, for-designers, for-artists, graphic-design, portrait, album-cover, doodle

Reviews

Loading reviews…

Discussion

Loading comments…