Pytest Writer logo

Pytest Writer

Organization
Ascend
pytest-writer

专业的pytest测试用例编写助手,用于创建、编写和优化Python测试用例。当需要编写测试文件、创建测试代码、重构优化测试、调试失败测试、使用fixtures、参数化测试、断言技巧、测试覆盖率分析时使用此技能。

Overview

PublisherAscend
Repositoryagent-skills
Skill namepytest-writer
Stars
54
Forks
4
Bundled files
5
LicenseMulanPSL-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by Ascend on GitHub. Read the source before you install it.

Installation

Install the Pytest Writer AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Ascend/agent-skills/tree/master/skills/mindspeed-llm-auto-ut-skills/skills/pytest-writer
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Ascend/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/mindspeed-llm-auto-ut-skills/skills/pytest-writer .claude/skills/pytest-writer
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Pytest Writer in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Pytest Writer on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Pytest Writer is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Pytest Writer

Overview

使用pytest框架编写高质量、可维护的Python测试用例。支持简单断言、自动发现、fixtures、参数化测试等pytest核心特性。

Quick Start

基本测试结构

python
# test_sample.py
def inc(x):
    return x + 1

def test_answer():
    assert inc(3) == 4

运行测试:

bash
pytest

测试文件命名规范

  • 测试文件:test_*.py 或 *_test.py
  • 测试函数:test_*
  • 测试类:Test*

Core Capabilities

1. 编写基本测试

使用简单的assert语句,pytest提供详细的失败信息:

python
def test_addition():
    assert 1 + 1 == 2

def test_string_operations():
    text = "hello"
    assert text.upper() == "HELLO"
    assert len(text) == 5

2. 使用Fixtures

Fixtures用于管理测试资源和依赖关系:

python
import pytest

@pytest.fixture
def sample_data():
    return {"name": "test", "value": 42}

def test_with_fixture(sample_data):
    assert sample_data["value"] == 42

高级fixtures用法:参见 references/fixtures.md

3. 参数化测试

使用@pytest.mark.parametrize减少重复代码:

python
@pytest.mark.parametrize("input,expected", [
    (3, 4),
    (5, 6),
    (10, 11),
])
def test_increment(input, expected):
    assert input + 1 == expected

更多参数化模式:参见 references/parametrize.md

4. 断言技巧

利用pytest的断言内省功能:

python
def test_dict_comparison():
    expected = {"a": 1, "b": 2}
    actual = {"a": 1, "b": 3}
    assert actual == expected  # pytest会显示详细的差异

断言最佳实践:参见 references/assertions.md

5. 测试组织

按功能组织
tests/
├── test_auth.py
├── test_database.py
├── test_api.py
└── conftest.py  # 共享fixtures
使用conftest.py

在conftest.py中定义共享fixtures:

python
# conftest.py
@pytest.fixture
def db_connection():
    conn = create_connection()
    yield conn
    conn.close()

6. 异常测试

使用pytest.raises测试异常:

python
def test_zero_division():
    with pytest.raises(ZeroDivisionError):
        1 / 0

def test_value_error():
    with pytest.raises(ValueError) as exc_info:
        int("invalid")
    assert "invalid literal" in str(exc_info.value)

7. 跳过和预期失败

python
@pytest.mark.skip(reason="功能未实现")
def test_not_implemented():
    pass

@pytest.mark.skipif(sys.version_info < (3, 8), reason="需要Python 3.8+")
def test_python38_feature():
    pass

@pytest.mark.xfail
def test_known_failure():
    assert False  # 预期失败

Testing Best Practices

测试命名

  • 使用描述性的测试名称:test_user_login_with_valid_credentials
  • 遵循AAA模式:Arrange(准备)→ Act(执行)→ Assert(断言)
python
def test_calculate_total_with_discount():
    # Arrange
    cart = Cart(items=[Item(price=100), Item(price=50)])
    discount = 0.1
    
    # Act
    total = cart.calculate_total(discount)
    
    # Assert
    assert total == 135

测试隔离

  • 每个测试应该独立运行
  • 使用fixtures确保测试间的隔离
  • 避免测试间的依赖关系

更多最佳实践:参见 references/best-practices.md

Running Tests

基本命令

bash
# 运行所有测试
pytest

# 运行特定文件
pytest tests/test_auth.py

# 运行特定测试函数
pytest tests/test_auth.py::test_login

# 运行匹配模式的测试
pytest -k "login"

# 显示详细输出
pytest -v

# 显示print语句输出
pytest -s

# 在第一个失败时停止
pytest -x

# 运行上次失败的测试
pytest --lf

测试覆盖率

bash
# 生成覆盖率报告
pytest --cov=src

# 生成HTML报告
pytest --cov=src --cov-report=html

Debugging Failed Tests

查看详细错误信息

bash
pytest -v --tb=long

使用pdb调试

python
def test_debugging():
    import pdb; pdb.set_trace()
    result = complex_calculation()
    assert result == expected

或在命令行:

bash
pytest --pdb

Resources

references/

详细参考文档:

assets/

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Pytest Writer AI skill do?

专业的pytest测试用例编写助手,用于创建、编写和优化Python测试用例。当需要编写测试文件、创建测试代码、重构优化测试、调试失败测试、使用fixtures、参数化测试、断言技巧、测试覆盖率分析时使用此技能。

Why use Pytest Writer on TypingMind?

Because you install it once and use it with any model. Pytest Writer is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Pytest Writer in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Ascend/agent-skills/tree/master/skills/mindspeed-llm-auto-ut-skills/skills/pytest-writer. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Pytest Writer?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Pytest Writer?

As many as you like. As long as a model supports skills, you can use Pytest Writer with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Pytest Writer AI skill free?

Yes. It is published on GitHub by Ascend under the MulanPSL-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇