Files
haikdcandGitHub 9c95342704 Haik/feat/test runner (#86)
* [haik]: ckpt, added in the test runner skelton i made in another repo -> still gotta make tweaks to fold it onto the current repo

* [haik]: restructure backend test layout: move 37 test files from backend/tests/ into backend/tests/test_cases/, add backend/tests/run.sh one-command launcher that auto-provisions both runner and test venvs with stamp-based caching, update runner config.json to point test_paths at test_cases/ and fix venv_python path, revise runner README with run.sh usage and clearer setup instructions, and gitignore the .runner-venv directory

* [haik]: refactor: reorganize backend/tests/test_cases from flat structure into domain subdirectories — moved 36 test files into auth/, browser/, labeling/, service/, settings/, and web_search/ for better discoverability and grouping

* [haik]: overhaul test picker UI and add post-run rerun loop: replace checkbox glyphs with fzf-style row recolouring (coral=full, lighter coral=partial) and a right-pinned selection dot, add config-driven icon tiers (nerd/emoji/unicode/ascii) with per-glyph graceful degradation, replace the modal -k keyword screen with an inline live-filtering search bar that prunes the tree on every keystroke, add warm Anthropic-dark coral theme, toolbar flag chips replacing the old status line, and a floating help badge overlay; add rerun_prompt.py with inline Textual pill prompt (rerun all/failed/passed/exit) shown after each TTY run, wire it into main.py as a post-run loop; change run_tests to return (exit_code, RunSummary) tracking collected/passed/failed node IDs via new Dashboard methods; add icons field to config.py and config.json (set to nerd), document icon tiers and Nerd Font setup in README, set Hack Nerd Font in .vscode/settings.json, add .runner-venv to linter excludes
2026-06-14 07:02:30 -07:00

57 lines
1.8 KiB
Python

"""Test discovery by delegating to pytest's own collector.
We never parse test files ourselves — we ask pytest to collect and emit node
IDs. This matches pytest exactly (handles asyncio_mode=auto, parametrization,
classes, markers) instead of guessing from decorators like the old runner did.
Collection runs in the configured *test* venv (``config.venv_python``), because
collecting imports the test modules and therefore needs the project's full test
dependencies — not the runner's own venv.
"""
from __future__ import annotations
import subprocess
from tests.runner.config import load_config
_CONFIG = load_config()
# Kept for backwards-compatible imports (e.g. run.py uses it for relpath).
REPO_ROOT = _CONFIG.repo_root
# Default search roots come from config; we avoid scanning tests/runner itself.
DEFAULT_PATHS: list[str] = _CONFIG.test_paths
def discover(paths: list[str] | None = None, keyword: str | None = None) -> list[str]:
"""Return pytest node IDs for the given paths (optionally -k filtered).
Raises RuntimeError if pytest collection itself errored.
"""
search = paths or DEFAULT_PATHS
cmd = [
_CONFIG.venv_python,
"-m",
"pytest",
"-o",
"addopts=", # drop the global -q so node IDs print one per line
"--collect-only",
"-q",
*search,
]
if keyword:
cmd += ["-k", keyword]
proc = subprocess.run(
cmd, capture_output=True, text=True, cwd=str(REPO_ROOT)
)
# Collection errors (import errors, bad -k) → surface stderr/stdout.
if proc.returncode not in (0, 5): # 5 = "no tests collected"
raise RuntimeError(
f"pytest collection failed (exit {proc.returncode}):\n"
f"{proc.stdout}\n{proc.stderr}".strip()
)
return [line.strip() for line in proc.stdout.splitlines() if "::" in line]