pytest-gen

GitHub

用于生成Python pytest测试代码的Skill,涵盖测试组织、覆盖率要求及模板结构。

.github/skills/pytest-gen/SKILL.md github/copilot-cli-for-beginners

Trigger Scenarios

生成pytest测试 创建测试套件 为Python代码编写测试

Install

npx skills add github/copilot-cli-for-beginners --skill pytest-gen -g -y
More Options

Non-standard path

npx skills add https://github.com/github/copilot-cli-for-beginners/tree/main/.github/skills/pytest-gen -g -y

Use without installing

npx skills use github/copilot-cli-for-beginners@pytest-gen

指定 Agent (Claude Code)

npx skills add github/copilot-cli-for-beginners --skill pytest-gen -a claude-code -g -y

安装 repo 全部 skill

npx skills add github/copilot-cli-for-beginners --all -g -y

预览 repo 内 skill

npx skills add github/copilot-cli-for-beginners --list

SKILL.md

Frontmatter
{
    "name": "pytest-gen",
    "description": "Generate comprehensive pytest tests - use when generating tests, creating test suites, or testing Python code"
}

Pytest Generation Skill

When generating tests, follow this structure.

Test Organization

  • Group tests by function under test
  • Use @pytest.mark.parametrize for multiple inputs
  • Use fixtures for shared setup
  • Follow arrange/act/assert pattern

Coverage Requirements

  • Happy path (expected usage)
  • Edge cases (empty strings, None, boundary values)
  • Error cases (invalid input, file not found, wrong types)
  • Integration (functions working together)

Template

import pytest
from module_under_test import function_to_test


@pytest.fixture
def sample_data():
    """Provide shared test data."""
    return {"key": "value"}


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

    def test_happy_path(self, sample_data):
        result = function_to_test(valid_input)
        assert result == expected_output

    def test_empty_input(self):
        result = function_to_test("")
        assert result == expected_for_empty

    @pytest.mark.parametrize("input_val,expected", [
        ("valid", True),
        ("", False),
        (None, False),
    ])
    def test_various_inputs(self, input_val, expected):
        assert function_to_test(input_val) == expected

Version History

  • 82632dc Current 2026-07-25 07:29

Same Skill Collection

.github/skills/code-checklist/SKILL.md
.github/skills/commit-message/SKILL.md
.github/skills/hello-world/SKILL.md
samples/skills/code-checklist/SKILL.md
samples/skills/commit-message/SKILL.md
samples/skills/hello-world/SKILL.md
samples/skills/pytest-gen/SKILL.md

Metadata

Files
0
Version
7f0fd69
Hash
1cecbc7a
Indexed
2026-07-25 07:29

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-23 01:50
浙ICP备14020137号-1