Index
provide.testkit.quality.coverage
¶
Coverage analysis integration for provide-testkit.
Provides pytest fixtures and utilities for tracking code coverage during tests. Integrates with the coverage.py library for comprehensive coverage analysis.
Features: - Automatic coverage tracking during test runs - Coverage reporting in multiple formats - Integration with quality gates - Artifact management for CI/CD
Usage
Basic coverage tracking¶
def test_with_coverage(coverage_tracker): result = coverage_tracker.start() # ... run tests coverage_tracker.stop() assert coverage_tracker.get_coverage() > 90
Session-wide coverage¶
def test_example(session_coverage): # Coverage automatically tracked across all tests pass
Classes¶
CoverageFixture
¶
Bases: BaseQualityFixture
Pytest fixture for coverage tracking integration.
Initialize coverage fixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Coverage configuration |
None
|
artifact_dir
|
Path | None
|
Directory for artifacts |
None
|
Source code in provide/testkit/quality/coverage/fixture.py
CoverageReporter
¶
Specialized reporter for coverage results.
Initialize coverage reporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Reporter configuration |
None
|
Source code in provide/testkit/quality/coverage/reporter.py
Functions¶
format_html_summary
¶
Format coverage result as HTML summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Coverage result to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
HTML summary |
Source code in provide/testkit/quality/coverage/reporter.py
format_json_report
¶
Format coverage result as JSON data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Coverage result to format |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
JSON-serializable report data |
Source code in provide/testkit/quality/coverage/reporter.py
format_terminal_report
¶
Format coverage result for terminal output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Coverage result to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted terminal report |
Source code in provide/testkit/quality/coverage/reporter.py
generate_dashboard_data
¶
Generate data for coverage dashboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Coverage result |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dashboard data structure |
Source code in provide/testkit/quality/coverage/reporter.py
CoverageTracker
¶
Wrapper for coverage.py library with testkit integration.
Provides high-level interface for coverage tracking with automatic artifact management and integration with the quality framework.
Initialize coverage tracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Coverage configuration options |
None
|
Source code in provide/testkit/quality/coverage/tracker.py
Functions¶
analyze
¶
Run coverage analysis on the given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to analyze |
required |
**kwargs
|
Any
|
Additional options including artifact_dir |
{}
|
Returns:
| Type | Description |
|---|---|
QualityResult
|
QualityResult with coverage data |
Source code in provide/testkit/quality/coverage/tracker.py
generate_report
¶
Generate coverage report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str
|
Report format (terminal, html, xml, json) |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Report content (for terminal/json) or path (for html/xml) |
Source code in provide/testkit/quality/coverage/tracker.py
get_coverage
¶
Get current coverage percentage.
Returns:
| Type | Description |
|---|---|
float
|
Coverage percentage (0-100) |
Source code in provide/testkit/quality/coverage/tracker.py
report
¶
Generate report from QualityResult (implements QualityTool protocol).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Coverage result |
required |
format
|
str
|
Report format |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted report |
Source code in provide/testkit/quality/coverage/tracker.py
start
¶
Start coverage tracking.
Source code in provide/testkit/quality/coverage/tracker.py
stop
¶
Stop coverage tracking and save data.
Functions¶
coverage_tracker
¶
coverage_tracker(
request: FixtureRequest, tmp_path: Path
) -> Generator[CoverageFixture, None, None]
Pytest fixture for coverage tracking.
Provides a CoverageFixture instance that automatically starts and stops coverage tracking around individual tests.
Usage
def test_with_coverage(coverage_tracker): coverage_tracker.start_tracking() # ... test code coverage_tracker.stop_tracking() assert coverage_tracker.get_coverage() > 80
Source code in provide/testkit/quality/coverage/fixture.py
session_coverage
¶
Session-wide coverage tracking.
Tracks coverage across all tests in the session. Useful for getting overall coverage metrics for the entire test suite.
Usage
def test_part_one(session_coverage): # Coverage tracked across all tests pass
def test_part_two(session_coverage): # Same coverage instance pass