Test runner
test_runner
Agent-optimized test runner with structured output.
Wraps pytest with pytest-json-report to produce compact,
token-efficient results for AI coding agents.
FailureDetail
dataclass
Structured detail for a single test failure.
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
error_type
instance-attribute
Exception class name, e.g. AssertionError.
file
instance-attribute
Relative file path.
line
instance-attribute
Line number of the assertion / raising statement.
message
instance-attribute
One-line error message.
test
instance-attribute
Full node ID, e.g. tests/unit/test_x.py::TestFoo::test_bar.
traceback
instance-attribute
Short traceback (truncated to _MAX_TB_LINES).
TestReport
dataclass
Compact test execution report.
All fields use None rather than empty containers when no data
exists so that dataclasses.asdict produces a minimal payload.
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
build_pytest_cmd(*, report_path, coverage_path, files, markers, stop_on_first)
Build the pytest command line.
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
build_test_report(*, report_data, total_cov, per_file_cov, mode=None, last_coverage=None)
Build a TestReport from pytest JSON and coverage data.
Always parses failures and populates coverage — no mode branching.
Returns None for failures and coverage_by_file when no
data exists.
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
parse_collector_errors(collectors)
Extract FailureDetail items from pytest-json-report collectors list.
Collector errors occur before test discovery completes (e.g.
SyntaxError in a test file, broken imports).
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
parse_coverage(coverage_path)
Parse coverage JSON into total % and per-file dict.
Files whose basename equals __main__.py are excluded from the
per-file map (they typically contain only a python -m entry
point and are not meaningfully unit-testable). The aggregate
total_pct from pytest-cov is left untouched, in line with
coverage.py's exclude_also convention of filtering reports
rather than rewriting the underlying totals.
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
parse_failures(tests)
Extract FailureDetail items from pytest-json-report tests list.
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
parse_json_report(report_path)
Read and parse a pytest-json-report JSON file.
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
run_tests(project_path, *, mode='failures', files=None, markers=None, stop_on_first=True)
Run tests with agent-optimized structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
Path
|
Root of the project to test. |
required |
mode
|
str
|
Accepted for backward compatibility but ignored — all modes now produce the same unified output (failures + coverage). |
'failures'
|
files
|
list[str] | None
|
Specific test files or paths to run. |
None
|
markers
|
list[str] | None
|
Pytest markers to filter ( |
None
|
stop_on_first
|
bool
|
Stop on first failure ( |
True
|
Returns:
| Type | Description |
|---|---|
TestReport
|
Structured |
Source code in packages/axm-audit/src/axm_audit/core/test_runner.py
| Python | |
|---|---|
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |