Skip to content

ditto.exceptions

Exception hierarchy for pytest-ditto errors.

DittoWarning

Bases: UserWarning

Category for all pytest-ditto advisory warnings.

Subclasses UserWarning, so a blanket ignore::UserWarning still applies; use ignore::ditto.exceptions.DittoWarning to silence only ditto's advisories, or error::ditto.exceptions.DittoWarning to escalate them.

DittoUnknownRecorderError(name, available)

Bases: DittoException

Raised when a requested recorder is not installed.

Source code in ditto/exceptions.py
def __init__(self, name: str, available: list[str]) -> None:
    available_str = ", ".join(sorted(available)) if available else "(none)"
    super().__init__(
        f"Unknown ditto recorder {name!r}. Available recorders: {available_str}."
    )

DittoRecorderLoadError(name, distribution, cause, hint='')

Bases: DittoException

Raised when an installed recorder's entry point fails to load.

Source code in ditto/exceptions.py
def __init__(
    self, name: str, distribution: str, cause: BaseException, hint: str = ""
) -> None:
    message = (
        f"ditto recorder {name!r} from {distribution} failed to load: "
        f"{type(cause).__name__}: {cause}"
    )
    super().__init__(f"{message}. {hint}" if hint else message)

DittoRecorderConflictError

Bases: DittoException

Raised when a recorder registration breaks the plugin contract.

Raised when a conflicted recorder is looked up, and when register is given a name that would conflict. The message describes the conflict and names the distributions involved.

DittoJSONSerializationError(path, detail)

Bases: DittoException

Raised for values outside ditto's strict JSON data model.

Source code in ditto/exceptions.py
def __init__(self, path: str, detail: str) -> None:
    super().__init__(
        f"Strict JSON rejected the value at {path}: {detail}. "
        "Use only exact built-in None, bool, int, finite float, str, list, "
        "and dict values with exact string keys, or select another recorder."
    )

DittoUnhashableStorageOptionsError(value)

Bases: DittoException

Raised when ditto_storage_options contains an unhashable value.

Source code in ditto/exceptions.py
def __init__(self, value: object) -> None:
    super().__init__(
        f"ditto_storage_options contains an unhashable value ({value!r}, "
        f"type {type(value).__name__}). Backend cache identity requires every "
        "storage option to be hashable: two resolutions of the same logical "
        "target would otherwise silently get separate backend instances, "
        "breaking session-lifecycle tracking (prune, lock) for that target. "
        "Pass a hashable equivalent, or wrap the value so identity can be "
        "established some other way."
    )