{"id":"temporal-python-testing","name":"temporal-python-testing","summary":"pytest、タイムスキッピング、モッキング戦略で時間ワークフローをテストしてください。ユニットテスト、統合テスト、リプレイテスト、ローカル開発セットアップをカバーしています。","body":"# Temporal Python Testing Strategies\n\nComprehensive testing approaches for Temporal workflows using pytest, progressive disclosure resources for specific testing scenarios.\n\n## When to Use This Skill\n\n- **Unit testing workflows** - Fast tests with time-skipping\n- **Integration testing** - Workflows with mocked activities\n- **Replay testing** - Validate determinism against production histories\n- **Local development** - Set up Temporal server and pytest\n- **CI/CD integration** - Automated testing pipelines\n- **Coverage strategies** - Achieve ≥80% test coverage\n\n## Testing Philosophy\n\n**Recommended Approach** (Source: docs.temporal.io/develop/python/testing-suite):\n\n- Write majority as integration tests\n- Use pytest with async fixtures\n- Time-skipping enables fast feedback (month-long workflows → seconds)\n- Mock activities to isolate workflow logic\n- Validate determinism with replay testing\n\n**Three Test Types**:\n\n1. **Unit**: Workflows with time-skipping, activities with ActivityEnvironment\n2. **Integration**: Workers with mocked activities\n3. **End-to-end**: Full Temporal server with real activities (use sparingly)\n\n## Available Resources\n\nThis skill provides detailed guidance through progressive disclosure. Load specific resources based on your testing needs:\n\n### Unit Testing Resources\n\n**File**: `resources/unit-testing.md`\n**When to load**: Testing individual workflows or activities in isolation\n**Contains**:\n\n- WorkflowEnvironment with time-skipping\n- ActivityEnvironment for activity testing\n- Fast execution of long-running workflows\n- Manual time advancement patterns\n- pytest fixtures and patterns\n\n### Integration Testing Resources\n\n**File**: `resources/integration-testing.md`\n**When to load**: Testing workflows with mocked external dependencies\n**Contains**:\n\n- Activity mocking strategies\n- Error injection patterns\n- Multi-activity workflow testing\n- Signal and query testing\n- Coverage strategies\n\n### Replay Testing Resources\n\n**File**: `resources/replay-testing.md`\n**When to load**: Validating determinism or deploying workflow changes\n**Contains**:\n\n- Determinism validation\n- Production history replay\n- CI/CD integration patterns\n- Version compatibility testing\n\n### Local Development Resources\n\n**File**: `resources/local-setup.md`\n**When to load**: Setting up development environment\n**Contains**:\n\n- Docker Compose configuration\n- pytest setup and configuration\n- Coverage tool integration\n- Development workflow\n\n## Quick Start Guide\n\n### Basic Workflow Test\n\n```python\nimport pytest\nfrom temporalio.testing import WorkflowEnvironment\nfrom temporalio.worker import Worker\n\n@pytest.fixture\nasync def workflow_env():\n    env = await WorkflowEnvironment.start_time_skipping()\n    yield env\n    await env.shutdown()\n\n@pytest.mark.asyncio\nasync def test_workflow(workflow_env):\n    async with Worker(\n        workflow_env.client,\n        task_queue=\"test-queue\",\n        workflows=[YourWorkflow],\n        activities=[your_activity],\n    ):\n        result = await workflow_env.client.execute_workflow(\n            YourWorkflow.run,\n            args,\n            id=\"test-wf-id\",\n            task_queue=\"test-queue\",\n        )\n        assert result == expected\n```\n\n### Basic Activity Test\n\n```python\nfrom temporalio.testing import ActivityEnvironment\n\nasync def test_activity():\n    env = ActivityEnvironment()\n    result = await env.run(your_activity, \"test-input\")\n    assert result == expected_output\n```\n\n## Coverage Targets\n\n**Recommended Coverage** (Source: docs.temporal.io best practices):\n\n- **Workflows**: ≥80% logic coverage\n- **Activities**: ≥80% logic coverage\n- **Integration**: Critical paths with mocked activities\n- **Replay**: All workflow versions before deployment\n\n## Key Testing Principles\n\n1. **Time-Skipping** - Month-long workflows test in seconds\n2. **Mock Activities** - Isolate workflow logic from external dependencies\n3. **Replay Testing** - Validate determinism before deployment\n4. **High Coverage** - ≥80% target for production workflows\n5. **Fast Feedback** - Unit tests run in milliseconds\n\n## How to Use Resources\n\n**Load specific resource when needed**:\n\n- \"Show me unit testing patterns\" → Load `resources/unit-testing.md`\n- \"How do I mock activities?\" → Load `resources/integration-testing.md`\n- \"Setup local Temporal server\" → Load `resources/local-setup.md`\n- \"Validate determinism\" → Load `resources/replay-testing.md`\n\n## Additional References\n\n- Python SDK Testing: docs.temporal.io/develop/python/testing-suite\n- Testing Patterns: github.com/temporalio/temporal/blob/main/docs/development/testing.md\n- Python Samples: github.com/temporalio/samples-python","author":"@wshobson","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/wshobson/agents/tree/main/plugins/backend-development/skills/temporal-python-testing","license":"MIT","category":"writing","lang":"en","tokens":956,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"resources/integration-testing.md","size":12991,"sha256":"9c5b5d1ed33b7c3e536c197824f7ac42ae647df7f7369182f66efbc58f9d7ae3"},{"path":"resources/local-setup.md","size":12065,"sha256":"d407ca7c4a285d6f2c031b4740a4b8d5bf5840f656c6b68deb2877e00860cc97"},{"path":"resources/replay-testing.md","size":12381,"sha256":"f7e2e3ae1f1f9d7fbb547bd5639e97cdd7d7ef4bbae9887897520182e4cad51e"},{"path":"resources/unit-testing.md","size":8710,"sha256":"4fe310c3fb54cc44ab0178983546daa4785f4023ea7f0b92e3418096ddf289a8"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":["api.example.com"]}}