improving-python-coverage

Runs Python tests with coverage and implements unit tests to raise coverage by 0.2%.

45.7k|4.4k|Updated Aug 24, 2019
One-click install
npx skills add https://github.com/streamlit/streamlit --skill improving-python-coverage
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: improving-python-coverage
Source: https://github.com/streamlit/streamlit/tree/main/.claude/skills/improving-python-coverage
Command: npx skills add https://github.com/streamlit/streamlit --skill improving-python-coverage

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python projects accumulate untested code paths that hide bugs in conditional branches, error handling, and edge cases. This Skill automates the cycle of measuring coverage, identifying high-impact gaps, and writing meaningful unit tests until coverage improves by a defined target.

Core Features & Use Cases

  • Coverage Analysis: Runs the test suite with coverage, generates a JSON report, and prioritizes files by size and missing lines while skipping protobufs, vendor code, and already well-covered modules.
  • Autonomous Test Implementation: Delegates test writing to subagents that follow project conventions such as pytest-style functions, parametrize, numpydoc docstrings, and integration-test markers.
  • Iterative Verification: Re-runs tests and coverage until the 0.2% improvement target is met, then simplifies and reviews the changes.
  • Use Case: A maintainer of the Streamlit repository wants to steadily raise unit test coverage in lib/streamlit without manually hunting for uncovered lines or writing boilerplate tests.

Quick Start

Ask the assistant to improve Python test coverage in this repository and let it run the coverage analysis and test-writing loop autonomously.

Frequently Asked Questions about improving-python-coverage

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I increase Python test coverage automatically?

Run the test suite with coverage, export a JSON report, and prioritize files with large size and low percent_covered. Then write pytest tests targeting missing lines in conditional branches, error handling, and edge cases, and re-measure until the target gain is reached.

How to find uncovered lines in a Python project?

Generate a coverage JSON report with coverage json, which lists per-file missing_lines arrays. Focus on core modules with below-average coverage and skip files above 97 percent, protobuf, vendor, and static directories.

What kinds of tests should I write to improve coverage?

Test conditional logic, error handling, edge cases like None, empty, zero, and max values, and public API functions. Avoid testing simple accessors, protobufs, and implementation details that add no real bug-catching value.

How do I handle tests that need optional dependencies?

Import integration-only packages inside the test function rather than at module top level, and mark the test with pytest.mark.require_integration. This lets the test skip gracefully when those packages are not installed in the unit test environment.

Why does local coverage differ from CI coverage?

Version-specific branches for Python or library versions only run on matching CI jobs, and integration tests run in separate CI jobs with extra packages installed. Verify whether uncovered lines are exercised in CI before adding tests or pragma no cover annotations.

When should I use pragma no cover in Python?

Use it sparingly for platform-specific branches, defensive code that should never execute, or abstract method stubs, always with a reason comment. Do not use it to hide testable logic just to inflate coverage numbers.