CheckResult

CheckResult(
    name,
    status,
    message,
    details=list(),
    duration=0.0,
    findings=list(),
    skip_reason=None,
)

Result of a single check.

Contains the outcome of running a check, including the status, a human-readable message, and optional details. People read the message and the details. Programs read the findings and the skip reason.

Attributes

name : str

Name of the check that produced this result (e.g., “metadata”).

status : CheckStatus

The status of the check (OK, WARNING, ERROR, etc.).

message : str

Human-readable message describing the result.

details : list[str]

Optional list of detailed messages providing more context.

duration : float

Time taken to run the check in seconds.

findings : list[Finding]

What the check found, one Finding for each. Empty when the status is OK or SKIPPED.

skip_reason : str | None

One of SKIP_REASONS when the status is SKIPPED, and None otherwise.

Examples

Create a successful check result:

>>> result = CheckResult(
...     name="metadata",
...     status=CheckStatus.OK,
...     message="Package metadata is valid",
... )
>>> result.status
<CheckStatus.OK: 'ok'>

Create a result with details:

>>> result = CheckResult(
...     name="linting",
...     status=CheckStatus.WARNING,
...     message="Found 3 linting issues",
...     details=["Line 10: E501 line too long", "Line 20: W503 line break"],
... )
>>> print(result)
⚠ linting: Found 3 linting issues

Methods

Name Description
skip Build the result of a check that did not look at anything.
to_dict Convert to dictionary for JSON serialization.

skip

CheckResult.skip(name, message, reason, details=())

Build the result of a check that did not look at anything.

Parameters

name : str

Name of the check.

message : str

Human-readable message that says why it was skipped.

reason : str

One of SKIP_REASONS.

details : list[str] | tuple[str, …] = ()

Optional detail lines, as a list or a tuple. A bare string is not accepted by the type, since it would become one detail for each character.

Returns

: CheckResult

A SKIPPED result with that reason and no findings.

Examples

>>> result = CheckResult.skip(
...     "typing", "No type checker configured", "not-configured"
... )
>>> result.status, result.skip_reason
(<CheckStatus.SKIPPED: 'skipped'>, 'not-configured')

to_dict

CheckResult.to_dict()

Convert to dictionary for JSON serialization.

Returns

: dict[str, Any]

A dictionary with keys: name, status, message, details, duration,

: dict[str, Any]

findings, skip_reason. The status is converted to its string

: dict[str, Any]

value and each finding to a dictionary.

Examples

>>> result = CheckResult("test", CheckStatus.OK, "Passed")
>>> result.to_dict()
{'name': 'test', 'status': 'ok', 'message': 'Passed',
 'details': [], 'duration': 0.0, 'findings': [],
 'skip_reason': None}