Skip to content

Audit test

audit_test

MCP tool for structured test execution.

AuditTestTool

Bases: AXMTool

Run tests with structured output.

Registered as audit_test via axm.tools entry point.

Source code in packages/axm-audit/src/axm_audit/tools/audit_test.py
Python
class AuditTestTool(AXMTool):
    """Run tests with structured output.

    Registered as ``audit_test`` via axm.tools entry point.
    """

    @property
    def name(self) -> str:
        """Return tool name for registry lookup."""
        return "audit_test"

    def execute(
        self,
        *,
        path: str = ".",
        mode: str = "failures",
        files: list[str] | None = None,
        markers: list[str] | None = None,
        stop_on_first: bool = True,
        **kwargs: object,
    ) -> ToolResult:
        """Run tests with structured output.

        Args:
            path: Path to project root.
            mode: Deprecated, ignored. Kept for backward compatibility.
            files: Specific test files to run.
            markers: Pytest markers to filter.
            stop_on_first: Stop on first failure.

        Returns:
            ToolResult with structured test report.
        """
        if mode != "failures":
            logger.info("mode param is deprecated")

        try:
            project_path = Path(path).resolve()
            if not project_path.is_dir():
                return ToolResult(
                    success=False, error=f"Not a directory: {project_path}"
                )

            from axm_audit.core.test_runner import run_tests

            report = run_tests(
                project_path,
                files=files,
                markers=markers,
                stop_on_first=stop_on_first,
            )

            data = dataclasses.asdict(report)

            from axm_audit.tools.audit_test_text import format_audit_test_text

            text = format_audit_test_text(report)

            return ToolResult(success=True, data=data, text=text)
        except Exception as exc:  # noqa: BLE001
            return ToolResult(success=False, error=str(exc))
name property

Return tool name for registry lookup.

execute(*, path='.', mode='failures', files=None, markers=None, stop_on_first=True, **kwargs)

Run tests with structured output.

Parameters:

Name Type Description Default
path str

Path to project root.

'.'
mode str

Deprecated, ignored. Kept for backward compatibility.

'failures'
files list[str] | None

Specific test files to run.

None
markers list[str] | None

Pytest markers to filter.

None
stop_on_first bool

Stop on first failure.

True

Returns:

Type Description
ToolResult

ToolResult with structured test report.

Source code in packages/axm-audit/src/axm_audit/tools/audit_test.py
Python
def execute(
    self,
    *,
    path: str = ".",
    mode: str = "failures",
    files: list[str] | None = None,
    markers: list[str] | None = None,
    stop_on_first: bool = True,
    **kwargs: object,
) -> ToolResult:
    """Run tests with structured output.

    Args:
        path: Path to project root.
        mode: Deprecated, ignored. Kept for backward compatibility.
        files: Specific test files to run.
        markers: Pytest markers to filter.
        stop_on_first: Stop on first failure.

    Returns:
        ToolResult with structured test report.
    """
    if mode != "failures":
        logger.info("mode param is deprecated")

    try:
        project_path = Path(path).resolve()
        if not project_path.is_dir():
            return ToolResult(
                success=False, error=f"Not a directory: {project_path}"
            )

        from axm_audit.core.test_runner import run_tests

        report = run_tests(
            project_path,
            files=files,
            markers=markers,
            stop_on_first=stop_on_first,
        )

        data = dataclasses.asdict(report)

        from axm_audit.tools.audit_test_text import format_audit_test_text

        text = format_audit_test_text(report)

        return ToolResult(success=True, data=data, text=text)
    except Exception as exc:  # noqa: BLE001
        return ToolResult(success=False, error=str(exc))