Skip to content

Commit cd06c5c

Browse files
update pytest-cov to include integration tests (#583)
and also generate coverage reports
1 parent 7e7d25b commit cd06c5c

File tree

6 files changed

+302
-5
lines changed

6 files changed

+302
-5
lines changed

libs/aws/CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,61 @@ To run the integration tests:
7676
make integration_test
7777
```
7878

79+
### Code Coverage
80+
81+
This project uses [coverage.py](https://github.com/nedbat/coveragepy) to track code coverage during testing. Coverage reports help identify untested code paths and ensure comprehensive test coverage.
82+
83+
#### Running Tests with Coverage
84+
85+
To run unit tests with coverage:
86+
87+
```bash
88+
make coverage_tests
89+
```
90+
91+
To run all integration tests with coverage:
92+
93+
```bash
94+
make coverage_integration_tests
95+
```
96+
97+
To run a specific integration test with coverage:
98+
99+
```bash
100+
make coverage_integration_test TEST_FILE=tests/integration_tests/specific_test.py
101+
```
102+
103+
#### Viewing Coverage Reports
104+
105+
After running tests with coverage, you can view the results in several ways:
106+
107+
**Terminal Report:**
108+
```bash
109+
make coverage_report
110+
```
111+
112+
**HTML Report:**
113+
```bash
114+
make coverage_html
115+
```
116+
117+
The HTML report will be generated in the `htmlcov/` directory. Open `htmlcov/index.html` in your browser to view detailed line-by-line coverage analysis.
118+
119+
#### Coverage Configuration
120+
121+
Coverage settings are configured in `pyproject.toml`:
122+
- **Source tracking**: Only code in `langchain_aws/` is measured
123+
- **Branch coverage**: Tracks both line and branch coverage for comprehensive analysis
124+
- **Exclusions**: Test files and common patterns (like `pragma: no cover`) are excluded
125+
- **Reports**: Both terminal and HTML reports show missing lines and coverage percentages
126+
127+
#### Coverage Best Practices
128+
129+
- Aim for high coverage on new code you add
130+
- Use coverage reports to identify untested edge cases
131+
- Add tests for uncovered lines when practical
132+
- Use `# pragma: no cover` sparingly for truly untestable code (like debug statements)
133+
79134
### Formatting and Linting
80135

81136
Formatting ensures that the code in this repo has consistent style so that the

libs/aws/Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######################
22
# NON FILE TARGETS
33
######################
4-
.PHONY: all format lint test tests integration_tests docker_tests help extended_tests
4+
.PHONY: all format lint test tests integration_tests docker_tests help extended_tests coverage_integration_tests coverage_integration_test coverage_tests coverage_report coverage_html
55

66
######################
77
# ALL TARGETS
@@ -35,6 +35,21 @@ integration_test: ## Run individual integration test: make integration_test TEST
3535
test_watch: ## Run and interactively watch unit tests
3636
poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE)
3737

38+
coverage_integration_tests: ## Run integration tests with coverage
39+
poetry run pytest --cov=langchain_aws --cov-report=html --cov-report=term-missing --cov-branch tests/integration_tests/
40+
41+
coverage_integration_test: ## Run specific integration test with coverage: make coverage_integration_test TEST_FILE=tests/integration_tests/integ_test.py
42+
poetry run pytest --cov=langchain_aws --cov-report=html --cov-report=term-missing --cov-branch $(TEST_FILE)
43+
44+
coverage_tests: ## Run unit tests with coverage
45+
poetry run pytest --cov=langchain_aws --cov-report=html --cov-report=term-missing --cov-branch tests/unit_tests/
46+
47+
coverage_report: ## Generate coverage report
48+
poetry run coverage report
49+
50+
coverage_html: ## Generate HTML coverage report
51+
poetry run coverage html
52+
3853
######################
3954
# LINTING AND FORMATTING
4055
######################

libs/aws/pyproject.toml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,33 @@ disallow_untyped_defs = "True"
8989
exclude = ["notebooks", "samples"]
9090

9191
[tool.coverage.run]
92-
omit = ["tests/*"]
92+
source = ["langchain_aws"]
93+
omit = [
94+
"tests/*",
95+
"*/tests/*",
96+
"test_*",
97+
"*_test.py"
98+
]
99+
branch = true
100+
101+
[tool.coverage.report]
102+
exclude_lines = [
103+
"pragma: no cover",
104+
"def __repr__",
105+
"if self.debug:",
106+
"if settings.DEBUG",
107+
"raise AssertionError",
108+
"raise NotImplementedError",
109+
"if 0:",
110+
"if __name__ == .__main__.:",
111+
"class .*\\bProtocol\\):",
112+
"@(abc\\.)?abstractmethod"
113+
]
114+
precision = 2
115+
show_missing = true
116+
117+
[tool.coverage.html]
118+
directory = "htmlcov"
93119

94120
[build-system]
95121
requires = ["poetry-core>=1.0.0"]
@@ -105,7 +131,7 @@ build-backend = "poetry.core.masonry.api"
105131
#
106132
# https://github.com/tophat/syrupy
107133
# --snapshot-warn-unused Prints a warning on unused snapshots rather than fail the test suite.
108-
addopts = "--snapshot-warn-unused --strict-markers --strict-config --durations=5 --cov=langchain_aws"
134+
addopts = "--snapshot-warn-unused --strict-markers --strict-config --durations=5"
109135
# Registering custom markers.
110136
# https://docs.pytest.org/en/7.1.x/example/markers.html#registering-markers
111137
markers = [

libs/langgraph-checkpoint-aws/CONTRIBUTING.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,157 @@ Contributions via pull requests are much appreciated. Before sending us a pull r
2828
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
2929

3030

31+
## Development Setup
32+
33+
This section provides detailed instructions for setting up your development environment and running tests locally.
34+
35+
### Prerequisites
36+
37+
This project utilizes [Poetry](https://python-poetry.org/) v1.7.1+ as a dependency manager.
38+
39+
❗Note: *Before installing Poetry*, if you use `Conda`, create and activate a new Conda env (e.g. `conda create -n langgraph-checkpoint-aws python=3.9`)
40+
41+
Install Poetry: **[documentation on how to install it](https://python-poetry.org/docs/#installation)**.
42+
43+
❗Note: If you use `Conda` or `Pyenv` as your environment/package manager, after installing Poetry,
44+
tell Poetry to use the virtualenv python environment (`poetry config virtualenvs.prefer-active-python true`)
45+
46+
### Installation
47+
48+
All commands should be run from the `libs/langgraph-checkpoint-aws` directory:
49+
50+
```bash
51+
cd libs/langgraph-checkpoint-aws
52+
```
53+
54+
Install all development dependencies:
55+
56+
```bash
57+
poetry install --with dev,test,lint,typing,codespell,test_integration
58+
```
59+
60+
### Testing
61+
62+
#### Unit Tests
63+
64+
Unit tests cover modular logic that does not require calls to outside APIs:
65+
66+
```bash
67+
make tests
68+
```
69+
70+
To run a specific unit test:
71+
72+
```bash
73+
make test TEST_FILE=tests/unit_tests/specific_test.py
74+
```
75+
76+
#### Integration Tests
77+
78+
Integration tests cover end-to-end functionality with AWS services:
79+
80+
```bash
81+
make integration_tests
82+
```
83+
84+
To run a specific integration test:
85+
86+
```bash
87+
make integration_test TEST_FILE=tests/integration_tests/specific_test.py
88+
```
89+
90+
### Code Coverage
91+
92+
This project uses [coverage.py](https://github.com/nedbat/coveragepy) to track code coverage during testing.
93+
94+
#### Running Tests with Coverage
95+
96+
To run unit tests with coverage:
97+
98+
```bash
99+
make coverage_tests
100+
```
101+
102+
To run all integration tests with coverage:
103+
104+
```bash
105+
make coverage_integration_tests
106+
```
107+
108+
To run a specific integration test with coverage:
109+
110+
```bash
111+
make coverage_integration_test TEST_FILE=tests/integration_tests/specific_test.py
112+
```
113+
114+
#### Viewing Coverage Reports
115+
116+
**Terminal Report:**
117+
```bash
118+
make coverage_report
119+
```
120+
121+
**HTML Report:**
122+
```bash
123+
make coverage_html
124+
```
125+
126+
The HTML report will be generated in the `htmlcov/` directory. Open `htmlcov/index.html` in your browser for detailed analysis.
127+
128+
### Code Quality
129+
130+
#### Formatting
131+
132+
Code formatting is done via [ruff](https://docs.astral.sh/ruff/rules/):
133+
134+
```bash
135+
make format
136+
```
137+
138+
#### Linting
139+
140+
Linting is done via [ruff](https://docs.astral.sh/ruff/rules/):
141+
142+
```bash
143+
make lint
144+
```
145+
146+
To automatically fix linting issues:
147+
148+
```bash
149+
make lint_fix
150+
```
151+
152+
#### Type Checking
153+
154+
Type checking is done via [mypy](http://mypy-lang.org/):
155+
156+
```bash
157+
make lint_tests
158+
```
159+
160+
#### Spell Checking
161+
162+
Spell checking is done via [codespell](https://github.com/codespell-project/codespell):
163+
164+
```bash
165+
make spell_check
166+
```
167+
168+
To fix spelling issues:
169+
170+
```bash
171+
make spell_fix
172+
```
173+
174+
### Clean Up
175+
176+
To clean generated files and caches:
177+
178+
```bash
179+
make clean
180+
```
181+
31182
## Finding contributions to work on
32183
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
33184

libs/langgraph-checkpoint-aws/Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PYTHON_FILES=.
66
MYPY_CACHE=.mypy_cache
77
PACKAGE_NAME=langgraph_checkpoint_aws
88

9-
.PHONY: help lint format install_dev install_test install_lint install_typing install_codespell check_imports spell_check spell_fix
9+
.PHONY: help lint format install_dev install_test install_lint install_typing install_codespell check_imports spell_check spell_fix coverage_integration_tests coverage_integration_test coverage_tests coverage_report coverage_html
1010

1111
######################
1212
# LINTING AND FORMATTING
@@ -72,6 +72,21 @@ integration_test: ## Run individual integration test: make integration_test TEST
7272
test_watch: ## Run and interactively watch unit tests
7373
poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE)
7474

75+
coverage_integration_tests: ## Run integration tests with coverage
76+
poetry run pytest --cov=langgraph_checkpoint_aws --cov-report=html --cov-report=term-missing --cov-branch tests/integration_tests/
77+
78+
coverage_integration_test: ## Run specific integration test with coverage: make coverage_integration_test TEST_FILE=tests/integration_tests/integ_test.py
79+
poetry run pytest --cov=langgraph_checkpoint_aws --cov-report=html --cov-report=term-missing --cov-branch $(TEST_FILE)
80+
81+
coverage_tests: ## Run unit tests with coverage
82+
poetry run pytest --cov=langgraph_checkpoint_aws --cov-report=html --cov-report=term-missing --cov-branch tests/unit_tests/
83+
84+
coverage_report: ## Generate coverage report
85+
poetry run coverage report
86+
87+
coverage_html: ## Generate HTML coverage report
88+
poetry run coverage html
89+
7590
######################
7691
# DEPENDENCIES
7792
######################

libs/langgraph-checkpoint-aws/pyproject.toml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,39 @@ ignore-words-list = ''
7878
ignore_missing_imports = "True"
7979

8080
[tool.coverage.run]
81-
omit = ["tests/*"]
81+
source = ["langgraph_checkpoint_aws"]
82+
omit = [
83+
"tests/*",
84+
"*/tests/*",
85+
"test_*",
86+
"*_test.py"
87+
]
88+
branch = true
89+
90+
[tool.coverage.report]
91+
exclude_lines = [
92+
"pragma: no cover",
93+
"def __repr__",
94+
"if self.debug:",
95+
"if settings.DEBUG",
96+
"raise AssertionError",
97+
"raise NotImplementedError",
98+
"if 0:",
99+
"if __name__ == .__main__.:",
100+
"class .*\\bProtocol\\):",
101+
"@(abc\\.)?abstractmethod"
102+
]
103+
precision = 2
104+
show_missing = true
105+
106+
[tool.coverage.html]
107+
directory = "htmlcov"
108+
109+
[tool.pytest.ini_options]
110+
addopts = "--strict-markers --strict-config --durations=5"
111+
markers = [
112+
"requires: mark tests as requiring a specific library",
113+
"asyncio: mark tests as requiring asyncio",
114+
"compile: mark placeholder test used to compile integration tests without running them",
115+
"scheduled: mark tests to run in scheduled testing",
116+
]

0 commit comments

Comments
 (0)