Skip to content
Python

fix: add coverage measurement and reporting to CI

Shakti Prasad Mohapatraf54d62724f10
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bacffd6e..e9cd0cc4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -17,8 +17,15 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e ".[messaging,dev,bedrock]"
- - name: Test
- run: pytest tests -q
+ - name: Test with coverage
+ run: pytest tests -q --cov=coworker --cov-report=term-missing --cov-report=xml
+ - name: Upload coverage report
+ if: always()
+ uses: actions/upload-artifact@v4
+ with:
+ name: coverage-report
+ path: coverage.xml
+ retention-days: 30
gui-unit:
runs-on: ubuntu-latest
diff --git a/pyproject.toml b/pyproject.toml
index bac15979..98f2c38c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -39,7 +39,7 @@ dependencies = [
]
[project.optional-dependencies]
-dev = ["pytest>=8", "pytest-asyncio", "httpx"]
+dev = ["pytest>=8", "pytest-asyncio", "pytest-cov>=5", "httpx"]
# Inbound messaging listeners (outbound send_message needs only httpx, already a core dep).
# aiohttp is slack-bolt's Socket Mode transport at runtime (and the FakeSlack test harness
# drives the real handler) — declare it so CI installs it, not just transitively.
@@ -74,3 +74,27 @@ testpaths = ["tests"]
# console script (CI) does not put the root on sys.path the way `python -m pytest` does.
pythonpath = ["."]
asyncio_mode = "auto"
+
+[tool.coverage.run]
+source = ["coworker"]
+branch = true
+omit = [
+ "*/tests/*",
+ "*/__pycache__/*",
+ "*/migrations/*",
+]
+
+[tool.coverage.report]
+show_missing = true
+skip_covered = false
+precision = 1
+# Ratchet floor — only goes up, never down.
+# Run `pytest tests --cov=coworker --cov-report=term-missing` to see current coverage.
+fail_under = 0
+exclude_lines = [
+ "pragma: no cover",
+ "def __repr__",
+ "raise NotImplementedError",
+ "if TYPE_CHECKING:",
+ "if __name__ == .__main__.:",
+]