Quality Tools¶
provide.testkit.quality
¶
Code quality analysis utilities for the provide testkit.
This module provides pytest fixtures and utilities for integrating code quality tools into testing workflows. All quality tools are optional and only activated when explicitly requested.
Key Features: - Coverage tracking and reporting - Security scanning with Bandit - Complexity analysis with Radon - Performance profiling with py-spy - Documentation coverage with Interrogate
Usage
Basic quality fixture¶
def test_with_coverage(quality_coverage): result = quality_coverage.track_coverage()
Quality decorator¶
@quality_check(coverage=90, security=True) def test_with_gates(): pass
CLI usage¶
provide-testkit quality analyze src/
Classes¶
BaseQualityFixture
¶
Bases: ABC
Base class for pytest quality fixtures.
Provides common functionality for quality analysis fixtures including configuration management, artifact handling, and result tracking.
Initialize the fixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Tool-specific configuration |
None
|
artifact_dir
|
Path | None
|
Directory to store artifacts |
None
|
Source code in provide/testkit/quality/base.py
Functions¶
setup
abstractmethod
¶
teardown
abstractmethod
¶
add_result
¶
get_results
¶
get_results_by_tool
¶
ensure_setup
¶
create_artifact_dir
¶
Create and return artifact directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subdir
|
str | None
|
Optional subdirectory name |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the artifact directory |
Source code in provide/testkit/quality/base.py
QualityResult
dataclass
¶
QualityResult(
tool: str,
passed: bool,
score: float | None = None,
details: dict[str, Any] = dict(),
artifacts: list[Path] = list(),
execution_time: float | None = None,
)
Result from a quality analysis tool.
Attributes:
| Name | Type | Description |
|---|---|---|
tool |
str
|
Name of the tool that generated this result |
passed |
bool
|
Whether the quality check passed |
score |
float | None
|
Numeric score (0-100) if applicable |
details |
dict[str, Any]
|
Tool-specific details and metrics |
artifacts |
list[Path]
|
List of artifact files created |
execution_time |
float | None
|
Time taken to run the analysis in seconds |
QualityTool
¶
Bases: Protocol
Protocol for quality analysis tools.
Functions¶
analyze
¶
Run analysis on the given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to analyze (file or directory) |
required |
**kwargs
|
Any
|
Tool-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
QualityResult
|
QualityResult containing analysis results |
Source code in provide/testkit/quality/base.py
report
¶
Generate a report from analysis result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Result to generate report for |
required |
format
|
str
|
Output format (terminal, json, html, markdown) |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted report string |
Source code in provide/testkit/quality/base.py
ReportGenerator
¶
Generates reports from quality analysis results.
Supports multiple output formats including terminal, JSON, HTML, and Markdown.
Initialize report generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Configuration for report generation |
None
|
Source code in provide/testkit/quality/report.py
Functions¶
generate
¶
Generate a report from quality results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, QualityResult]
|
Quality results to report on |
required |
format
|
str
|
Output format (terminal, json, html, markdown) |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted report string |
Source code in provide/testkit/quality/report.py
save_report
¶
save_report(
results: dict[str, QualityResult],
output_path: Path,
format: str | None = None,
) -> None
Save report to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, QualityResult]
|
Quality results to report on |
required |
output_path
|
Path
|
Path to save report to |
required |
format
|
str | None
|
Output format (auto-detected from extension if None) |
None
|
Source code in provide/testkit/quality/report.py
QualityRunner
¶
QualityRunner(
artifact_root: Path | None = None,
tools: list[str] | None = None,
config: dict[str, Any] | None = None,
)
Orchestrates multiple quality analysis tools.
Manages the execution of quality tools, artifact collection, and result aggregation with configurable quality gates.
Initialize the quality runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artifact_root
|
Path | None
|
Root directory for storing artifacts (defaults to .quality-artifacts) |
None
|
tools
|
list[str] | None
|
List of tool names to run (None for default set) |
None
|
config
|
dict[str, Any] | None
|
Configuration for tools and runner |
None
|
Source code in provide/testkit/quality/runner.py
Functions¶
run_all
¶
Run all configured quality tools on the target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Path
|
Path to analyze |
required |
**kwargs
|
Any
|
Additional arguments passed to tools |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, QualityResult]
|
Dictionary mapping tool names to their results |
Source code in provide/testkit/quality/runner.py
run_with_gates
¶
run_with_gates(
target: Path, gates: dict[str, Any], **kwargs: Any
) -> tuple[bool, dict[str, QualityResult]]
Run quality tools and check against quality gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Path
|
Path to analyze |
required |
gates
|
dict[str, Any]
|
Quality gate requirements |
required |
**kwargs
|
Any
|
Additional arguments passed to tools |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[bool, dict[str, QualityResult]]
|
Tuple of (all_gates_passed, results) |
Source code in provide/testkit/quality/runner.py
get_available_tools
¶
generate_summary_report
¶
Generate a summary report of all results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, QualityResult]
|
Results to summarize |
required |
Returns:
| Type | Description |
|---|---|
str
|
Summary report string |
Source code in provide/testkit/quality/runner.py
run_tools
¶
run_tools(
target: Path,
tools: list[str] | None = None,
artifact_dir: Path | None = None,
tool_configs: dict[str, Any] | None = None,
) -> dict[str, QualityResult]
Run specific quality tools on the target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Path
|
Path to analyze |
required |
tools
|
list[str] | None
|
List of tool names to run (None for all available) |
None
|
artifact_dir
|
Path | None
|
Directory for artifacts (overrides default) |
None
|
tool_configs
|
dict[str, Any] | None
|
Configuration for tools |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, QualityResult]
|
Dictionary mapping tool names to their results |