Skip to content

Commit a85f145

Browse files
pepegapepega
authored andcommitted
feat(lab03): add coverage threshold and improve CI
- Add pyproject.toml with 70% coverage threshold - Configure pytest-cov fail-under for CI enforcement - Add codecov upload for Go workflow - Update LAB03.md with new coverage stats (98%) - Simplify pytest command to use pyproject.toml config Coverage improvements: - Python: 98% coverage with 70% threshold - Go: 67.2% coverage with codecov integration
1 parent 26e7014 commit a85f145

4 files changed

Lines changed: 48 additions & 10 deletions

File tree

.github/workflows/go-ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ jobs:
103103
- name: 📊 Display coverage
104104
run: go tool cover -func=coverage.out
105105

106+
- name: 📤 Upload coverage to Codecov
107+
uses: codecov/codecov-action@v4
108+
with:
109+
file: app_go/coverage.out
110+
flags: go-unittests
111+
name: codecov-go
112+
fail_ci_if_error: false
113+
token: ${{ secrets.CODECOV_TOKEN }}
114+
106115
# ==========================================================================
107116
# Job 3: Security Scanning with Snyk
108117
# ==========================================================================

.github/workflows/python-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
run: python -m ruff check .
7070

7171
- name: Run unit tests with coverage
72-
run: python -m pytest -v --cov=app --cov-report=xml --cov-report=term tests/
72+
run: python -m pytest tests/
7373

7474
- name: Upload coverage to Codecov
7575
uses: codecov/codecov-action@v4

app_python/docs/LAB03.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ push/PR → lint-test (3.11) ─┬─→ docker-build-push → Docker Hub
138138
### Test Coverage Integration
139139

140140
- **Tool:** pytest-cov + codecov.io
141-
- **Current Coverage:** 80% (41/51 lines)
141+
- **Current Coverage:** 98% (40/41 lines)
142+
- **Threshold:** 70% minimum (configured in `pyproject.toml`)
142143
- **Upload:** Automated to codecov.io on each push
143144
- **Badge:** Added to app_python/README.md
145+
- **Fail on low coverage:** CI fails if coverage drops below 70%
144146

145147
---
146148

@@ -149,7 +151,7 @@ push/PR → lint-test (3.11) ─┬─→ docker-build-push → Docker Hub
149151
### Local Tests with Coverage
150152

151153
```
152-
$ python -m pytest --cov=app --cov-report=term tests/
154+
$ python -m pytest tests/
153155
========================== test session starts ==========================
154156
collected 15 items
155157
@@ -160,20 +162,21 @@ ___________ coverage: platform darwin, python 3.14.0-final-0 ____________
160162
161163
Name Stmts Miss Cover
162164
----------------------------
163-
app.py 51 10 80%
165+
app.py 41 1 98%
164166
----------------------------
165-
TOTAL 51 10 80%
167+
TOTAL 41 1 98%
166168
167-
========================== 15 passed in 0.08s ===========================
169+
Required test coverage of 70% reached. Total coverage: 97.56%
170+
========================== 15 passed in 0.10s ===========================
168171
```
169172

170173
**Coverage Analysis:**
171-
- **Overall Coverage:** 80%
172-
- **Lines Tested:** 41 out of 51 lines
174+
- **Overall Coverage:** 98%
175+
- **Lines Tested:** 40 out of 41 lines
176+
- **Coverage Threshold:** 70% (CI fails if below)
173177
- **What's Covered:** All HTTP endpoints, helper functions, error handlers
174178
- **What's NOT Covered:**
175-
- `if __name__ == '__main__'` block (entry point, not testable without subprocess)
176-
- Some edge case handling (not critical for this service)
179+
- `if __name__ == '__main__'` block (entry point, excluded in pyproject.toml)
177180

178181
### Local Lint
179182

app_python/pyproject.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[tool.pytest.ini_options]
2+
testpaths = ["tests"]
3+
python_files = ["test_*.py"]
4+
python_classes = ["Test*"]
5+
python_functions = ["test_*"]
6+
addopts = "-v --cov=app --cov-report=term --cov-report=xml --cov-fail-under=70"
7+
8+
[tool.coverage.run]
9+
source = ["."]
10+
omit = ["tests/*", "venv/*", ".venv/*", "__pycache__/*"]
11+
12+
[tool.coverage.report]
13+
exclude_lines = [
14+
"pragma: no cover",
15+
"if __name__ == .__main__.:",
16+
"raise NotImplementedError",
17+
]
18+
fail_under = 70
19+
20+
[tool.ruff]
21+
line-length = 100
22+
target-version = "py311"
23+
24+
[tool.ruff.lint]
25+
select = ["E", "F", "W", "I", "N", "UP", "B", "C4"]
26+
ignore = ["E501"]

0 commit comments

Comments
 (0)