setup_retryΒΆ

.. py:function:: setup_retry(context: ~typing.Any, max_retries: int | None = None, retry_tags: list[str] | None = None, retry_on: list[type[Exception] | str] | None = None, retry_delay: float | None = None, backoff_factor: float | None = None, on_retry: ~collections.abc.Callable[[~typing.Any, ~typing.Any, int, Exception | None], None] | None = None, max_total_retries: int | None = None) -> None :module: behave_retry

Configure retry on the behave context.

Call this in before_all in your environment.py.

This patches behave.model.Scenario.run so that failed scenarios are automatically re-run up to max_retries times.

Parameters with a default of None are read from environment variables when not provided explicitly. This lets behave-runner or CI systems control retry behavior without modifying environment.py.

:param context: Behave context object. :param max_retries: Maximum retries per scenario (0 = no retry). If None, reads BEHAVE_RETRY_MAX_RETRIES (default 0). :param retry_tags: Only retry scenarios with these tags. :param retry_on: Only retry on these exception types. :param retry_delay: Seconds to wait before each retry (0 = no delay). If None, reads BEHAVE_RETRY_DELAY (default 0.0). :param backoff_factor: Multiplier applied to retry_delay after each retry. Must be >= 1.0. If None, reads BEHAVE_RETRY_BACKOFF (default 1.0). :param on_retry: Optional callback invoked before each retry with (context, scenario, attempt, exception). :param max_total_retries: Global budget for total retries across all scenarios. None = unlimited. If None, reads BEHAVE_RETRY_MAX_TOTAL (default None).