跳到正文
cccskills
免费在 GitHub 公开

test-generator

Generate pytest test cases for Python functions and classes

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md1.9 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Test Generator Skill

You are a test generation expert. When generating tests, follow these guidelines:

Test Structure

Use pytest with the following structure:

import pytest
from module import function_to_test

class TestFunctionName:
    """Tests for function_name."""

    def test_basic_case(self):
        """Test the basic/happy path."""
        result = function_to_test(valid_input)
        assert result == expected_output

    def test_edge_case(self):
        """Test edge cases."""
        ...

    def test_error_handling(self):
        """Test error conditions."""
        with pytest.raises(ExpectedError):
            function_to_test(invalid_input)

Test Categories

1. Happy Path Tests

  • Test normal, expected inputs
  • Verify correct output

2. Edge Cases

  • Empty inputs (empty string, empty list, None)
  • Boundary values (0, -1, max int)
  • Single element collections

3. Error Cases

  • Invalid types
  • Out of range values
  • Missing required parameters

4. Integration Tests (if applicable)

  • Test interactions between components
  • Test with real dependencies where possible

Best Practices

  1. One assertion per test when possible
  2. Descriptive test names that explain what's being tested
  3. Use fixtures for common setup
  4. Use parametrize for testing multiple inputs
  5. Mock external dependencies

Example: Parametrized Test

@pytest.mark.parametrize("input,expected", [
    (0, 0),
    (1, 1),
    (5, 120),
    (10, 3628800),
])
def test_factorial(input, expected):
    assert factorial(input) == expected

Example: Testing Async Functions

import pytest

@pytest.mark.asyncio
async def test_async_function():
    result = await async_function()
    assert result == expected

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Building, compiling, and resolving dependency issues across languages

中文简介正在准备中。当前显示原文说明。

vstorm-co/pydantic-deepagents11032026年10月19日 更新

Review Python code for quality, security, and best practices

中文简介正在准备中。当前显示原文说明。

vstorm-co/pydantic-deepagents11032026年10月19日 更新

Systematic code review for bugs, security, style, and performance

中文简介正在准备中。当前显示原文说明。

vstorm-co/pydantic-deepagents11032026年10月19日 更新

Comprehensive data analysis skill for CSV files using Python and pandas

中文简介正在准备中。当前显示原文说明。

vstorm-co/pydantic-deepagents11032026年10月19日 更新

Working with diverse data formats: binary, text, structured, and custom

中文简介正在准备中。当前显示原文说明。

vstorm-co/pydantic-deepagents11032026年10月19日 更新

Best practices for creating research diagrams with Excalidraw MCP tools

中文简介正在准备中。当前显示原文说明。

vstorm-co/pydantic-deepagents11032026年10月19日 更新

查看 vstorm-co 的全部技能

报告此技能的问题