From c39affbf6bcc2a40c0f4637bbccbefb200051c9a Mon Sep 17 00:00:00 2001 From: Patrick Buckley Date: Mon, 2 Mar 2026 17:28:50 -0800 Subject: [PATCH] Add test coverage reporting and pre-commit hooks (#2) * Add test coverage reporting and pre-commit hooks - Add pytest-cov to test dependencies, configure coverage in pyproject.toml (branch coverage, static asset omission, standard exclusion patterns) - CI test job now runs with --cov and uploads coverage XML as artifact - Add .pre-commit-config.yaml with ruff (check + format) and mypy hooks Baseline coverage: 41% (482 tests, Python 3.13) * Fix Copilot review: add redis dep for pre-commit mypy, explicit --cov target - Add redis>=7.2 to mypy pre-commit hook additional_dependencies so mypy can resolve redis imports in isolated pre-commit environments - Use --cov=turnstone instead of bare --cov to explicitly scope coverage --- .github/workflows/ci.yml | 7 ++++++- .pre-commit-config.yaml | 16 ++++++++++++++++ pyproject.toml | 17 ++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6eb9d16..4b42f66a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,4 +40,9 @@ jobs: with: python-version: ${{ matrix.python-version }} - run: pip install -e ".[test,mq]" - - run: pytest tests/ -m "not live" -q + - run: pytest tests/ -m "not live" --cov=turnstone --cov-report=term-missing --cov-report=xml -q + - uses: actions/upload-artifact@v4 + if: always() + with: + name: coverage-${{ matrix.python-version }} + path: coverage.xml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..43aaeabd --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.9.10 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.14.1 + hooks: + - id: mypy + additional_dependencies: [types-redis>=4.6, redis>=7.2] + args: [--config-file=pyproject.toml] + pass_filenames: false + entry: mypy turnstone/ diff --git a/pyproject.toml b/pyproject.toml index cd16fbf3..ae2508eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ Repository = "https://github.com/turnstonelabs/turnstone" Issues = "https://github.com/turnstonelabs/turnstone/issues" [project.optional-dependencies] -test = ["pytest>=9.0"] +test = ["pytest>=9.0", "pytest-cov>=6.0"] dev = ["ruff>=0.9", "mypy>=1.14", "types-redis>=4.6"] mq = ["redis>=7.2"] console = ["redis>=7.2"] @@ -80,6 +80,21 @@ disallow_incomplete_defs = true check_untyped_defs = true no_implicit_optional = true +[tool.coverage.run] +source = ["turnstone"] +branch = true +omit = ["turnstone/*/static/*"] + +[tool.coverage.report] +show_missing = true +skip_empty = true +exclude_lines = [ + "pragma: no cover", + "if TYPE_CHECKING", + "raise NotImplementedError", + 'if __name__ == "__main__"', +] + [[tool.mypy.overrides]] module = ["sympy", "sympy.*", "numpy", "numpy.*"] ignore_missing_imports = true