diff --git a/server/pullwright/checks.py b/server/pullwright/checks.py index 1d2acac..efeffc6 100644 --- a/server/pullwright/checks.py +++ b/server/pullwright/checks.py @@ -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() @@ -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) diff --git a/server/tests/test_checks.py b/server/tests/test_checks.py index a52c02f..377dfd4 100644 --- a/server/tests/test_checks.py +++ b/server/tests/test_checks.py @@ -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("")