Testes e qualidade Fonte oficial
Aumente a cobertura de testes com pytest
Gere relatórios anotados, encontre linhas Python não executadas e adicione testes até alcançar cobertura integral do código analisado.
Ver código no GitHub Instala diretamente do repositório-fonte.
O que esta skill faz
Esta skill usa pytest e pytest-cov para localizar linhas sem cobertura. O relatório annotate marca trechos não executados, permitindo criar casos direcionados e repetir o ciclo até que os arquivos analisados atinjam 100%.
Quando usar
- Medir a cobertura de todo o projeto Python
- Analisar a cobertura de um módulo específico
- Localizar linhas não executadas por testes
- Adicionar casos para caminhos condicionais
- Repetir a suíte até eliminar lacunas
Como usar
- Revise o repositório e identifique a suíte e o módulo-alvo
- Execute pytest --cov --cov-report=annotate:cov_annotate
- Abra os relatórios dos arquivos abaixo de 100%
- Crie testes para as linhas marcadas com exclamação
- Repita a execução até atingir a meta ou documentar impedimentos
O que revisar antes de instalar
- Cobertura de linhas não comprova a qualidade dos testes
- A meta de 100% pode exigir casos de erro e caminhos raros
- A execução depende de pytest-cov e do ambiente do projeto
- Código inalcançável pode exigir revisão, não apenas novos testes
SKILL.md
--- 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.