RetryConfigΒΆ

.. py:class:: RetryConfig(max_retries: int = 0, retry_tags: list[str] = , retry_on: list[type[Exception] | str] = , retry_delay: float = 0.0, backoff_factor: float = 1.0, on_retry: ~collections.abc.Callable[[~typing.Any, ~typing.Any, int, Exception | None], None] | None = None, max_total_retries: int | None = None) :module: behave_retry :canonical: behave_retry.config.RetryConfig

Bases: :py:class:object

Configuration for retry behavior.

.. attribute:: max_retries

  Maximum number of retries per scenario (0 = no retry).

  :type: int

.. attribute:: retry_tags

  Only retry scenarios with these tags. Empty = retry all.

  :type: list[str]

.. attribute:: retry_on

  Only retry on these exception types or names. Empty = retry on any.
  Accepts exception classes (``AssertionError``) or strings
  (``"AssertionError"``, ``"mymod.MyError"``).

  :type: list[type[Exception] | str]

.. attribute:: retry_delay

  Seconds to wait before each retry (0 = no delay).

  :type: float

.. attribute:: backoff_factor

  Multiplier applied to ``retry_delay`` after each retry.
  Must be >= 1.0. With ``retry_delay=2.0`` and ``backoff_factor=2.0``,
  delays are 2s, 4s, 8s, ...

  :type: float

.. attribute:: on_retry

  Optional callback invoked before each retry with
  ``(context, scenario, attempt, exception)``.

  :type: collections.abc.Callable[[Any, Any, int, Exception | None], None] | None

.. attribute:: max_total_retries

  Global budget for total retries across all
  scenarios. ``None`` = unlimited. When the budget is exhausted,
  no more retries are attempted.

  :type: int | None

.. py:attribute:: RetryConfig.backoff_factor :module: behave_retry :type: float :value: 1.0

.. py:method:: RetryConfig.get_retry_delay(attempt: int) -> float :module: behave_retry

  Calculate the delay before the next retry for a given attempt.

  The delay is ``retry_delay * (backoff_factor ** (attempt - 1))``.
  For the first retry (attempt=1) the base ``retry_delay`` is used.
  Subsequent retries multiply by ``backoff_factor`` each time.

  :param attempt: The retry attempt number (1-based).

  :returns: The delay in seconds. Returns 0.0 if ``retry_delay`` is 0.

.. py:method:: RetryConfig.get_scenario_retries(tags: list[str], feature_tags: list[str] | None = None) -> int :module: behave_retry

  Get max retries for a scenario, checking ``@retry:N`` tag override.

  A ``@retry:N`` tag on the scenario overrides the global
  ``max_retries``. If the scenario has no ``@retry:N`` tag, the
  feature-level ``@retry:N`` tag is checked (if *feature_tags* is
  provided). ``@retry:0`` disables retry for this scenario.
  Negative values are clamped to ``0`` (no retry).

  :param tags: List of tag strings from a behave scenario.
  :param feature_tags: Optional list of tag strings from the parent
                       feature. Used as fallback when the scenario has no
                       ``@retry:N`` tag.

  :returns: The effective max retries for this scenario.

.. py:attribute:: RetryConfig.max_retries :module: behave_retry :type: int :value: 0

.. py:attribute:: RetryConfig.max_total_retries :module: behave_retry :type: int | None :value: None

.. py:attribute:: RetryConfig.on_retry :module: behave_retry :type: ~collections.abc.Callable[[~typing.Any, ~typing.Any, int, Exception | None], None] | None :value: None

.. py:attribute:: RetryConfig.retry_delay :module: behave_retry :type: float :value: 0.0

.. py:attribute:: RetryConfig.retry_on :module: behave_retry :type: list[type[Exception] | str]

.. py:attribute:: RetryConfig.retry_tags :module: behave_retry :type: list[str]

.. py:method:: RetryConfig.should_retry_exception(exc: type[Exception]) -> bool :module: behave_retry

  Check if exception type allows retry.

  If ``retry_on`` is empty, all exceptions trigger retry.
  Otherwise, the exception must be a subclass of one in the list.
  String entries are resolved to exception classes on first use
  and cached for subsequent calls.

  :param exc: The exception type to check.

  :returns: ``True`` if the exception is eligible for retry.

.. py:method:: RetryConfig.should_retry_tag(tags: list[str]) -> bool :module: behave_retry

  Check if scenario tags allow retry.

  If ``retry_tags`` is empty, all scenarios are eligible.
  Otherwise, the scenario must have at least one matching tag.
  Behave strips the leading ``@`` from tags, so both ``@flaky``
  and ``flaky`` are matched.

  :param tags: List of tag strings from a behave scenario.

  :returns: ``True`` if the scenario is eligible for retry.