Configuration¶
The PriorityConfig dataclass controls all behavior
of behave-priority. It is immutable (frozen) and validated at construction
time.
- class behave_priority.config.PriorityConfig(order: bool = False, reverse: bool = False, priority_tag: str | None = None, stop_after_failures: int | None = None, stop_on_critical: bool = False, critical_tag: str = 'critical', default_priority: int = 999, report: bool = False, report_format: Literal['text', 'json', 'csv'] = 'text', parallel_coord: bool = False)[source]¶
Bases:
objectImmutable configuration for priority execution.
All configuration is programmatic — no CLI flags.
- Variables:
order (bool) – Sort scenarios by priority (highest first).
reverse (bool) – Reverse sort order (lowest priority first).
priority_tag (str | None) – Tag name to run first (e.g.
"smoke").stop_after_failures (int | None) – Stop after N failed scenarios, or None to disable.
stop_on_critical (bool) – Stop if any critical scenario fails.
critical_tag (str) – Tag name that marks a scenario as critical.
default_priority (int) – Priority for scenarios without a priority tag.
report (bool) – Print execution report after run.
report_format (Literal['text', 'json', 'csv']) – Output format for the report (
"text","json", or"csv").parallel_coord (bool) – Enable cross-process fail-fast coordination via
BEHAVE_PRIORITY_COORD_DIRenv var. When True and the env var is set, workers share failure state via a file-based coordinator.
- Raises:
ValueError – If
stop_after_failuresis not a positive integer (or None), ifcritical_tagorpriority_tagis an empty string, ifdefault_priorityis negative, or ifreport_formatis not one of"text","json","csv".
Configuration Fields¶
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Sort scenarios by priority (highest first). When |
|
|
|
Reverse sort order. When |
|
|
|
Tag name to run first (e.g. |
|
|
|
Stop after N failed scenarios. |
|
|
|
Stop execution if any scenario tagged |
|
|
|
Tag name that marks a scenario as critical. Both the tag and the
|
|
|
|
Priority assigned to scenarios without any priority tag. Must be non-negative. |
|
|
|
Print the execution report after the run via
|
Validation¶
The following validations are performed at construction time:
stop_after_failuresmust be a positive integer orNone.critical_tagmust not be an empty string.priority_tagmust not be an empty string if provided (Noneis valid).default_prioritymust be non-negative.
Invalid values raise ValueError with a descriptive message.
Examples¶
Basic priority ordering:
from behave_priority import PriorityConfig
config = PriorityConfig(order=True)
Priority ordering with fail-fast:
config = PriorityConfig(
order=True,
stop_after_failures=3,
report=True,
)
Smoke tests first, stop on critical failure:
config = PriorityConfig(
order=True,
priority_tag="smoke",
stop_on_critical=True,
critical_tag="critical",
report=True,
)
Reversed order (highest priority number first):
config = PriorityConfig(order=True, reverse=True)
Custom default priority:
config = PriorityConfig(order=True, default_priority=100)
Immutability¶
PriorityConfig is a frozen dataclass with slots=True. Once created,
its fields cannot be modified:
config = PriorityConfig(order=True)
config.order = False # Raises FrozenInstanceError
This ensures that configuration remains consistent throughout the test run.