Skip to content

Commit 2e5def5

Browse files
philvarnerPhil Varner
andauthored
Rework dependencies and how pytest is run (#126)
## What I'm changing Previously, all of the dependencies across every workspace were installed and then the tests run. This is bad because packages can be used in code and pass tests even though the dependency is not correcly defined in the workspace's pyproject.toml. ## How I did it - refactored the workspace pyproject.toml's to have dev dependencies necessary to run pytest - created a test running script to install only the dependencies for each workspace and run their tests. ## Checklist - [X] Tests pass: `uv run pytest` - [X] Checks pass: `uv run pre-commit run --all-files` - [X] CHANGELOG is updated (if necessary) --------- Co-authored-by: Phil Varner <[email protected]>
1 parent 97c760c commit 2e5def5

File tree

11 files changed

+82
-28
lines changed

11 files changed

+82
-28
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
## Checklist
1010

11-
- [ ] Tests pass: `uv run pytest`
11+
- [ ] Tests pass: `./scripts/run-tests.sh`
1212
- [ ] Checks pass: `uv run pre-commit run --all-files`
1313
- [ ] CHANGELOG is updated (if necessary)

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Pre-Commit Hooks
3131
run: uv run pre-commit run --all-files
3232
- name: Test
33-
run: uv run pytest
33+
run: ./scripts/run-tests.sh
3434
- name: Validate test server
3535
run: uv run scripts/validate-stapi-fastapi
3636
- name: Docs

.pre-commit-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@ repos:
77
language: system
88
types: [python]
99
pass_filenames: false
10-
verbose: true
1110

1211
- id: ruff-format
1312
name: Format with ruff
1413
entry: uv run ruff format
1514
language: system
1615
types: [python]
1716
pass_filenames: false
18-
verbose: true
1917

2018
- id: mypy
2119
name: Check typing with mypy
2220
entry: uv run mypy
2321
language: system
2422
types: [python]
2523
pass_filenames: false
26-
verbose: true
2724

2825
- id: pymarkdown
2926
name: Markdownlint

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ uv sync
6262
Test:
6363

6464
```shell
65-
uv run pytest
65+
./scripts/run-tests.sh
6666
```
6767

6868
Check formatting and other lints:

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ dependencies = [
1313

1414
[dependency-groups]
1515
dev = [
16-
"pytest>=8.1.1",
1716
"mypy>=1.15.0",
18-
"pytest>=8.3.5",
1917
"ruff>=0.11.2",
2018
"pymarkdownlnt>=0.9.25",
2119
"pre-commit>=4.2.0",
2220
"pre-commit-hooks>=5.0.0",
23-
"fastapi[standard]>=0.115.12",
24-
"types-click>=7.1.8",
2521
"pygithub>=2.6.1",
26-
"respx>=0.22.0",
2722
]
2823
docs = [
2924
"mkdocs-material>=9.6.11",

pystapi-client/pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
authors = [
77
{ name = "Kaveh Karimi-Asli", email = "[email protected]" },
88
{ name = "Philip Weiss", email = "[email protected]" },
9-
{ name = "Stella Reinhardt", email = "[email protected]"}
9+
{ name = "Stella Reinhardt", email = "[email protected]" },
1010
]
1111
maintainers = [{ name = "Pete Gadomski", email = "[email protected]" }]
1212
keywords = ["stapi"]
@@ -18,6 +18,8 @@ dependencies = [
1818
"python-dateutil>=2.8.2",
1919
"click>=8.1.8",
2020
]
21+
[dependency-groups]
22+
dev = ["pytest>=8.3.5", "respx>=0.22.0", "types-click>=7.1.8"]
2123

2224
[project.scripts]
2325
stapi = "pystapi_client.scripts.cli:cli"

scripts/run-tests.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
# set -x # print each command before executing
4+
5+
for path in stapi-fastapi pystapi-validator pystapi-client stapi-pydantic; do
6+
name=$(basename "$path")
7+
8+
set +e
9+
echo "Running tests for package $name"
10+
uv sync --package "$name"
11+
uv run --package "$name" --directory "$path" pytest -p no:sugar
12+
code=$?
13+
set -e
14+
15+
case "$code" in
16+
0) : ;;
17+
5) echo " (no tests in $name, skipping)";;
18+
*) echo " pytest failed in $name (exit $code)"; exit "$code";;
19+
esac
20+
done
21+
22+
# finally just globally sync, so we don't just have the stapi-pydantic deps
23+
# since this script will commonly be used before commit, and pre-commit is needed then
24+
uv sync

scripts/validate-stapi-fastapi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
scripts="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
66
root=$(dirname "$scripts")
77

8-
uv run fastapi dev "$root/stapi-fastapi/tests/application.py" >/dev/null 2>&1 &
8+
uv run --package stapi-fastapi fastapi dev "$root/stapi-fastapi/tests/application.py" >/dev/null 2>&1 &
99
server_pid=$!
1010

1111
set +e

stapi-fastapi/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ dependencies = [
2424
"stapi-pydantic>=0.0.3",
2525
]
2626

27+
[dependency-groups]
28+
dev = [
29+
"fastapi[standard]>=0.115.0",
30+
"pytest>=8.3.5",
31+
]
32+
2733
[tool.hatch.build.targets.sdist]
2834
include = ["src/stapi_fastapi"]
2935

stapi-pydantic/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ authors = [
1010
requires-python = ">=3.11"
1111
dependencies = ["pydantic>=2.12", "cql2>=0.3.6", "geojson-pydantic>=1.2.0"]
1212

13+
[dependency-groups]
14+
dev = [
15+
"pytest>=8.3.5",
16+
]
17+
1318
[project.scripts]
1419
stapi-pydantic = "stapi_pydantic:main"
1520

0 commit comments

Comments
 (0)