Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion server/pullwright/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ def _node_runner(root: Path) -> str:
return "npm"


def _has_python_tests(root: Path, pyproject: str) -> bool:
"""Recognize common pytest layouts and configuration files."""
return (
_has(root, "tests", "test", "pytest.ini", "tox.ini")
or any(root.glob("*_test.py"))
or any(root.glob("test_*.py"))
or bool(re.search(r"^\s*\[tool:pytest\]\s*$", _read(root / "setup.cfg"), re.IGNORECASE | re.MULTILINE))
or "pytest" in pyproject
)


def detect(root: Path) -> CheckPlan:
"""Best-effort setup and checks from the project files. One ecosystem per repo root."""
plan = CheckPlan()
Expand All @@ -100,7 +111,7 @@ def detect(root: Path) -> CheckPlan:
plan.checks["lint"] = f"{run}ruff check ."
if "mypy" in pyproject:
plan.checks["typecheck"] = f"{run}mypy ."
if _has(root, "tests", "test") or "pytest" in pyproject:
if _has_python_tests(root, pyproject):
plan.checks["test"] = f"{run}pytest -q"
elif _has(root, "package.json"):
runner = _node_runner(root)
Expand Down
20 changes: 20 additions & 0 deletions server/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ def test_detects_a_uv_python_project(tmp_path: Path):
assert plan.checks == {"lint": "uv run ruff check .", "test": "uv run pytest -q"}


def test_detects_pytest_from_standalone_test_modules(tmp_path: Path):
(tmp_path / "pyproject.toml").write_text("[project]\nname='x'\n")
for filename in ("test_widget.py", "widget_test.py"):
(tmp_path / filename).write_text("")
assert checks.detect(tmp_path).checks == {"test": "python -m pytest -q"}
(tmp_path / filename).unlink()


def test_detects_pytest_configuration_files(tmp_path: Path):
(tmp_path / "pyproject.toml").write_text("[project]\nname='x'\n")
for filename, content in (
("pytest.ini", ""),
("setup.cfg", "[tool:pytest]\n"),
("tox.ini", "[tox]\n"),
):
(tmp_path / filename).write_text(content)
assert checks.detect(tmp_path).checks == {"test": "python -m pytest -q"}
(tmp_path / filename).unlink()


def test_detects_node_scripts_with_the_lockfiles_runner(tmp_path: Path):
(tmp_path / "package.json").write_text(json.dumps({"scripts": {"build": "vite build", "test": "vitest", "lint": "eslint ."}}))
(tmp_path / "pnpm-lock.yaml").write_text("")
Expand Down
Loading