跳到正文
Skillpedia
测试48k · #5958

temporal-python-testing

它能做什么

这项技能可以帮助你使用 pytest 工具,测试运行在 Temporal 平台上的程序(称为“工作流”)。它会教你如何进行快速且可靠的测试。

适用场景

  • ✓当你想测试某个“工作流”本身能否正常运行时。
  • ✓当你想测试某个“工作流”如何与程序的其他部分交互时。
  • ✓当你想确保“工作流”的行为始终保持一致时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/temporal-python-testing/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/temporal-python-testing/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我如何测试我的工作流,让它即使在现实中需要很长时间,也能非常快速地运行?”

每周 5 个新技能,1 分钟读完。

工作原理

它使用 pytest 工具来运行测试。为了加快测试速度,它会模拟时间的流逝,使长时间运行的工作流能够在几秒内完成测试。它还会教你如何模拟程序的外部部分,这样你就可以只专注于“工作流”本身。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Temporal Python Testing Strategies

Comprehensive testing approaches for Temporal workflows using pytest, progressive disclosure resources for specific testing scenarios.

Do not use this skill when

  • The task is unrelated to temporal python testing strategies
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.

Use this skill when

  • Unit testing workflows - Fast tests with time-skipping
  • Integration testing - Workflows with mocked activities
  • Replay testing - Validate determinism against production histories
  • Local development - Set up Temporal server and pytest
  • CI/CD integration - Automated testing pipelines
  • Coverage strategies - Achieve ≥80% test coverage

Testing Philosophy

Recommended Approach (Source: docs.temporal.io/develop/python/testing-suite):

  • Write majority as integration tests
  • Use pytest with async fixtures
  • Time-skipping enables fast feedback (month-long workflows → seconds)
  • Mock activities to isolate workflow logic
  • Validate determinism with replay testing

Three Test Types:

  1. Unit: Workflows with time-skipping, activities with ActivityEnvironment
  2. Integration: Workers with mocked activities
  3. End-to-end: Full Temporal server with real activities (use sparingly)

Available Resources

This skill provides detailed guidance through progressive disclosure. Load specific resources based on your testing needs:

Unit Testing Resources

File: resources/unit-testing.md When to load: Testing individual workflows or activities in isolation Contains:

  • WorkflowEnvironment with time-skipping
  • ActivityEnvironment for activity testing
  • Fast execution of long-running workflows
  • Manual time advancement patterns
  • pytest fixtures and patterns

Integration Testing Resources

File: resources/integration-testing.md When to load: Testing workflows with mocked external dependencies Contains:

  • Activity mocking strategies
  • Error injection patterns
  • Multi-activity workflow testing
  • Signal and query testing
  • Coverage strategies

Replay Testing Resources

File: resources/replay-testing.md When to load: Validating determinism or deploying workflow changes Contains:

  • Determinism validation
  • Production history replay
  • CI/CD integration patterns
  • Version compatibility testing

Local Development Resources

File: resources/local-setup.md When to load: Setting up development environment Contains:

  • Docker Compose configuration
  • pytest setup and configuration
  • Coverage tool integration
  • Development workflow

Quick Start Guide

Basic Workflow Test

import pytest
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Worker

@pytest.fixture
async def workflow_env():
    env = await WorkflowEnvironment.start_time_skipping()
    yield env
    await env.shutdown()

@pytest.mark.asyncio
async def test_workflow(workflow_env):
    async with Worker(
        workflow_env.client,
        task_queue="test-queue",
        workflows=[YourWorkflow],
        activities=[your_activity],
    ):
        result = await workflow_env.client.execute_workflow(
            YourWorkflow.run,
            args,
            id="test-wf-id",
            task_queue="test-queue",
        )
        assert result == expected

Basic Activity Test

from temporalio.testing import ActivityEnvironment

async def test_activity():
    env = ActivityEnvironment()
    result = await env.run(your_activity, "test-input")
    assert result == expected_output

Coverage Targets

Recommended Coverage (Source: docs.temporal.io best practices):

  • Workflows: ≥80% logic coverage
  • Activities: ≥80% logic coverage
  • Integration: Critical paths with mocked activities
  • Replay: All workflow versions before deployment

Key Testing Principles

  1. Time-Skipping - Month-long workflows test in seconds
  2. Mock Activities - Isolate workflow logic from external dependencies
  3. Replay Testing - Validate determinism before deployment
  4. High Coverage - ≥80% target for production workflows
  5. Fast Feedback - Unit tests run in milliseconds

How to Use Resources

Load specific resource when needed:

…

常见问题

Temporal 中的“工作流”是什么?

“工作流”是运行在 Temporal 平台上的程序,用于编排复杂且具有弹性的任务。

为什么要模拟活动(activities)?

模拟是指创建程序某一部分的假版本,以便单独测试另一部分。这有助于你专注于“工作流”,而不必担心其他部分是否正常。

什么是“回放测试”(replay testing)?

这是一种使用真实执行历史来运行“工作流”的测试,以确保它总是产生相同的结果,这对可靠性至关重要。

详情

作者的原始描述

Comprehensive testing approaches for Temporal workflows using pytest, progressive disclosure resources for specific testing scenarios.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5958
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能