360 Secure SkillHub
360 安全技能中心

pytest-coverage

该 Skill 指导使用 pytest 生成行覆盖报告,打开 cov_annotate 标注目录,查找以 ! 标记的未覆盖代码行,并为这些行补充测试,反复运行直到所有代码行均被测试覆盖。

github
热度 0.00
最近更新 2026-10-18 22:11:21
分类:开发依赖:代码执行 / 读写文件应用场景:代码生成 / 代码审查

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add github/awesome-copilot/pytest-coverage
Metadata
name
pytest-coverage
description
Run pytest tests with coverage, discover lines missing coverage, and increase coverage to 100%.

The goal is for the tests to cover all lines of code.

Generate a coverage report with:

pytest --cov --cov-report=annotate:cov_annotate

If you are checking for coverage of a specific module, you can specify it like this:

pytest --cov=your_module_name --cov-report=annotate:cov_annotate

You can also specify specific tests to run, for example:

pytest tests/test_your_module.py --cov=your_module_name --cov-report=annotate:cov_annotate

Open the cov_annotate directory to view the annotated source code. There will be one file per source file. If a file has 100% source coverage, it means all lines are covered by tests, so you do not need to open the file.

For each file that has less than 100% test coverage, find the matching file in cov_annotate and review the file.

If a line starts with a ! (exclamation mark), it means that the line is not covered by tests. Add tests to cover the missing lines.

Keep running the tests and improving coverage until all lines are covered.