Execution Report¶
The report module provides execution report collection, rendering, and serialization.
ReportEntry¶
- class behave_priority.report.ReportEntry(index: int, feature_name: str, scenario_name: str, priority: int, status: str, duration: float, is_critical: bool)[source]¶
Bases:
objectSingle scenario entry in the execution report.
- Variables:
index (int) – 1-based position in execution order.
feature_name (str) – Name or filename of the parent feature.
scenario_name (str) – Display name of the scenario.
priority (int) – Resolved priority value.
status (str) – Execution status (
"passed","failed", etc.).duration (float) – Execution time in seconds.
is_critical (bool) – Whether the scenario has the critical tag.
The ReportEntry dataclass represents a single
scenario in the execution report. Each entry is immutable and hashable.
Fields¶
Field |
Type |
Description |
|---|---|---|
|
|
1-based position in execution order. |
|
|
Name or filename of the parent feature. |
|
|
Display name of the scenario. |
|
|
Resolved priority value. |
|
|
Execution status: |
|
|
Execution time in seconds. |
|
|
Whether the scenario has the critical tag (including rule-level). |
ReportSummary¶
- class behave_priority.report.ReportSummary(total: int, passed: int, failed: int, skipped: int, undefined: int = 0, untested: int = 0, critical_total: int = 0, critical_passed: int = 0, critical_failed: int = 0, critical_skipped: int = 0, total_duration: float = 0.0, skipped_duration: float = 0.0, time_saved: float = 0.0)[source]¶
Bases:
objectAggregate statistics from the report.
- Variables:
total (int) – Total number of recorded scenarios.
passed (int) – Number of passed scenarios.
failed (int) – Number of failed scenarios.
skipped (int) – Number of skipped scenarios.
undefined (int) – Number of undefined scenarios.
untested (int) – Number of scenarios with a status not matching any known category.
critical_total (int) – Total number of critical scenarios.
critical_passed (int) – Number of passed critical scenarios.
critical_failed (int) – Number of failed critical scenarios.
critical_skipped (int) – Number of skipped critical scenarios.
total_duration (float) – Sum of all scenario durations in seconds.
skipped_duration (float) – Sum of skipped scenario durations in seconds.
time_saved (float) – Estimated time saved by skipping scenarios, using priority-bucketed averages of executed scenario durations.
The ReportSummary dataclass provides aggregate
statistics across all report entries.
Properties¶
``time_saved``: Estimated time saved by fail-fast skipping. Since skipped
scenarios have duration=0 (they never ran), the saved time is estimated
as the average duration of executed (non-skipped) scenarios multiplied by
the number of skipped scenarios.
time_saved = avg(executed_durations) * skipped_count
``pass_rate``: Percentage of passed scenarios excluding skipped ones.
Returns 0.0 when no scenarios were executed.
pass_rate = (passed / (total - skipped)) * 100
PriorityReport¶
- class behave_priority.report.PriorityReport(config: PriorityConfig)[source]¶
Bases:
objectCollects and renders execution order with priorities and timing.
- __init__(config: PriorityConfig) None[source]¶
Initialize the report collector.
- Parameters:
config – Configuration that controls report behavior.
- record(*, scenario_name: str, feature_name: str, priority: int, status: str, duration: float, is_critical: bool) None[source]¶
Record a scenario execution result.
- Parameters:
scenario_name – Display name of the scenario.
feature_name – Name or filename of the parent feature.
priority – Resolved priority value.
status – Execution status (
"passed","failed", etc.).duration – Execution time in seconds.
is_critical – Whether the scenario has the critical tag.
- render() str[source]¶
Render the full report as a formatted string.
Column widths for Feature and Scenario names are computed dynamically from the actual content, with a maximum of 40 characters to avoid excessive width. Names longer than the computed width are truncated with
....- Returns:
A human-readable report with a table of entries and summary.
- summary() ReportSummary[source]¶
Compute aggregate statistics.
The
time_savedestimation uses priority-bucketed averages: skipped scenarios are grouped into priority buckets (size 100) and each bucket’s average executed duration is used as the estimate. Buckets without executed scenarios fall back to the global average.- Returns:
A
ReportSummarywith counts, durations, and estimated time saved.
- to_csv() str[source]¶
Serialize report entries to a CSV string.
The summary is not included in CSV output. Each row represents one scenario entry.
- Returns:
A CSV string with a header row and one row per entry.
Methods¶
Method |
Description |
|---|---|
|
Record a scenario execution result. Called by |
|
Render the full report as a formatted string table. |
|
Compute and return a |
|
Serialize the report to a dictionary (JSON-compatible). |
Rendered Output¶
The render() method produces a human-readable table:
Priority Execution Report
=========================
# Priority Feature Scenario Status Duration
------------------------------------------------------------------
1 1 Login Successful login passed 1.23s
2 2 Login Failed login failed 0.45s
3 3 Login Account locked skipped 0.00s
Summary:
Critical: 0/1 passed
Total: 1 passed, 1 failed, 1 skipped
Time saved by fail-fast: 1.23s (estimated, 1 scenario(s) skipped)
Column widths for Feature and Scenario names are computed dynamically from
the actual content, with a maximum of 40 characters. Names longer than the
computed width are truncated with .... The minimum column width is the
length of the header label ("Feature" or "Scenario") to ensure
proper alignment.
Dictionary Serialization¶
The to_dict() method returns a JSON-compatible dictionary:
{
"entries": [
{
"index": 1,
"feature_name": "Login",
"scenario_name": "Successful login",
"priority": 1,
"status": "passed",
"duration": 1.23,
"is_critical": False
},
...
],
"summary": {
"total": 3,
"passed": 1,
"failed": 1,
"skipped": 1,
"undefined": 0,
"critical_total": 1,
"critical_passed": 0,
"critical_failed": 0,
"total_duration": 1.68,
"skipped_duration": 0.0,
"pass_rate": 50.0,
"time_saved": 1.23
}
}
This format is suitable for REST API responses, file storage, or further processing.
Examples¶
Recording scenarios:
from behave_priority import PriorityConfig, PriorityReport
config = PriorityConfig()
report = PriorityReport(config)
report.record(
scenario_name="Login test",
feature_name="Auth",
priority=1,
status="passed",
duration=1.5,
is_critical=True,
)
Getting summary statistics:
summary = report.summary()
print(f"Pass rate: {summary.pass_rate:.1f}%")
print(f"Time saved: {summary.time_saved:.2f}s")
Exporting to JSON:
import json
data = report.to_dict()
json_str = json.dumps(data, indent=2)