Skip to content

Commit 10b1025

Browse files
ci: Add code coverage check (#67)
* ci: Add code coverage check * increase cc to 90 * Update .coveragerc to decrease cc to 81 --------- Co-authored-by: Averi Kitsch <akitsch@google.com>
1 parent 86a6dbf commit 10b1025

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

.coveragerc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[run]
2+
branch = true
3+
omit =
4+
*/__init__.py
5+
6+
[report]
7+
show_missing = true
8+
fail_under = 81

DEVELOPER.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ substitutions:
5858
_VERSION: "3.8"
5959
```
6060

61-
Use `gcloud builds triggers import --source=trigger.yaml` create triggers via the command line
61+
Use `gcloud builds triggers import --source=trigger.yaml` to create triggers via the command line
6262

6363
#### Project Setup
6464

@@ -77,5 +77,17 @@ Use `gcloud builds triggers import --source=trigger.yaml` create triggers via th
7777

7878
To run Cloud Build tests on GitHub from external contributors, ie RenovateBot, comment: `/gcbrun`.
7979

80+
#### Code Coverage
81+
Please make sure your code is fully tested. The Cloud Build integration tests are run with the `pytest-cov` code coverage plugin. They fail for PRs with a code coverage less than the threshold specified in `.coveragerc`. If your file is inside the main module and should be ignored by code coverage check, add it to the `omit` section of `.coveragerc`.
82+
83+
Check for code coverage report in any Cloud Build integration test log.
84+
Here is a breakdown of the report:
85+
- `Stmts`: lines of executable code (statements).
86+
- `Miss`: number of lines not covered by tests.
87+
- `Branch`: branches of executable code (e.g an if-else clause may count as 1 statement but 2 branches; test for both conditions to have both branches covered).
88+
- `BrPart`: number of branches not covered by tests.
89+
- `Cover`: average coverage of files.
90+
- `Missing`: lines that are not covered by tests.
91+
8092

8193
[triggers]: https://console.cloud.google.com/cloud-build/triggers?e=13802955&project=langchain-spanner-testing

integration.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ steps:
2626
- id: Run integration tests
2727
name: python:${_VERSION}
2828
entrypoint: python
29-
args: ["-m", "pytest"]
29+
args: ["-m", "pytest", "--cov=langchain_google_spanner", "--cov-config=.coveragerc", "tests/"]
3030
env:
3131
- "PROJECT_ID=$PROJECT_ID"
3232
- "INSTANCE_ID=${_INSTANCE_ID}"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ test = [
4242
"mypy==1.10.0",
4343
"pytest==7.4.4",
4444
"pytest-asyncio==0.23.6",
45+
"pytest-cov==5.0.0"
4546
]
4647

4748
[build-system]

0 commit comments

Comments
 (0)