一键导入
external-gitcode-ascend-pytest-writer
专业的pytest测试用例编写助手,用于创建、编写和优化Python测试用例。当需要编写测试文件、创建测试代码、重构优化测试、调试失败测试、使用fixtures、参数化测试、断言技巧、测试覆盖率分析时使用此技能。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
专业的pytest测试用例编写助手,用于创建、编写和优化Python测试用例。当需要编写测试文件、创建测试代码、重构优化测试、调试失败测试、使用fixtures、参数化测试、断言技巧、测试覆盖率分析时使用此技能。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
评估 CANN 算子仓的「进阶教程 / 开发指南」类文档质量——通读文档 + 对照算子代码**静态**查证(默认不跑),按五轴(找得到/信得过/学得会/可操作/读得懂)找出 漏讲/讲不清/过时/对不上代码/概念讲错,产出带证据与改进建议的体检报告(MD + HTML)。涉及「评进阶教程 / 开发指南文档质量 / 文档对不对得上代码 / 教程审稿 / tutorial 体检 / 文档信不信得过」等意图时使用。只评不改不跑,只对着文档与代码出诊断。
Run NPU inference/training tests on a remote SSH server with vllm-ascend Docker container. Use when the user asks to test models on NPU, run inference on Ascend devices, or deploy models to an SSH server.
Track daily PRs and Issues from vllm-project/vllm and vllm-project/vllm-ascend, filter by model (DeepSeek/Qwen/GLM/MiniMax/Kimi) and tech topics (PD disaggregation, MTP, quantization, graph mode, performance), analyze with LLM, and generate a Markdown report. Use when user wants vllm daily tracker, PR/Issue digest, or Ascend inference ecosystem monitoring.
Automatically fetch InferenceX benchmark data and generate daily performance reports for LLM inference on various hardware (NVIDIA, AMD, etc.). Supports email delivery, data change detection, and 8k1k sequence length performance analysis. Use when needing to track LLM inference performance trends, compare hardware configurations, or monitor benchmark updates.
通用 PyTorch 项目 Ascend NPU 迁移可行性分析。系统化扫描代码库中的 CUDA/GPU 依赖,按 7 大域分类评估(设备层、注意力机制、自定义算子、分布式通信、精度策略、第三方依赖、编译加速),并基于 Wan2.2 实际迁移经验提供逐项替代方案。适用于评估任何 DiT/Transformer 类模型(视频生成、LLM、多模态等)在昇腾 NPU 上的运行可行性与迁移工作量估算。
End-to-end AscendC custom operator development for Ascend NPU in an ascend-kernel (csrc/ops + build.sh + torch_npu PyTorch custom op) project. Use to design, generate, build, test, document, and tune a new AscendC operator from a name and a math/functional spec. Covers project init, two-level tiling design, op_host/op_kernel code generation, framework registration, compile/install/debug, PyTorch-style API docs, precision evaluation and root-cause debugging, torch_npu.profiler performance benchmarking, performance optimization, and security code review.
| name | external-gitcode-ascend-pytest-writer |
| description | 专业的pytest测试用例编写助手,用于创建、编写和优化Python测试用例。当需要编写测试文件、创建测试代码、重构优化测试、调试失败测试、使用fixtures、参数化测试、断言技巧、测试覆盖率分析时使用此技能。 |
| original-name | pytest-writer |
| synced-from | https://gitcode.com/Ascend/agent-skills |
| synced-date | 2026-05-26 |
| synced-commit | 1f7666e7768a0ceb21bb1d40ce4b5179fcb6f1d6 |
| license | UNKNOWN |
使用pytest框架编写高质量、可维护的Python测试用例。支持简单断言、自动发现、fixtures、参数化测试等pytest核心特性。
# test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 4
运行测试:
pytest
test_*.py 或 *_test.pytest_*Test*使用简单的assert语句,pytest提供详细的失败信息:
def test_addition():
assert 1 + 1 == 2
def test_string_operations():
text = "hello"
assert text.upper() == "HELLO"
assert len(text) == 5
Fixtures用于管理测试资源和依赖关系:
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
使用@pytest.mark.parametrize减少重复代码:
@pytest.mark.parametrize("input,expected", [
(3, 4),
(5, 6),
(10, 11),
])
def test_increment(input, expected):
assert input + 1 == expected
更多参数化模式:参见 references/parametrize.md
利用pytest的断言内省功能:
def test_dict_comparison():
expected = {"a": 1, "b": 2}
actual = {"a": 1, "b": 3}
assert actual == expected # pytest会显示详细的差异
断言最佳实践:参见 references/assertions.md
tests/
├── test_auth.py
├── test_database.py
├── test_api.py
└── conftest.py # 共享fixtures
在conftest.py中定义共享fixtures:
# conftest.py
@pytest.fixture
def db_connection():
conn = create_connection()
yield conn
conn.close()
使用pytest.raises测试异常:
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)
@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 # 预期失败
test_user_login_with_valid_credentialsdef 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
更多最佳实践:参见 references/best-practices.md
# 运行所有测试
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
# 生成覆盖率报告
pytest --cov=src
# 生成HTML报告
pytest --cov=src --cov-report=html
pytest -v --tb=long
def test_debugging():
import pdb; pdb.set_trace()
result = complex_calculation()
assert result == expected
或在命令行:
pytest --pdb
详细参考文档: