pytest runs in CI on every push and pull request - #61
Merged
Conversation
The tests/ directory has had 8 test files and no workflow that runs them. Nothing gated them, so model unit tests got written in WasteMAP's backend/tests/fast instead — the only repo of the pair with test CI — which forced WasteMAP's suite to reach into private SWEET_python helpers (e.g. SWEET_python.advanced_dst_city._prevent_food_waste, flagged by Copilot on RMI/WasteMAP#772). Tests of this package's internals can now live in the repo that owns them. All 133 existing tests pass on Python 3.12 with the pinned lockfile. None are stale and none need a database, network access or environment variables: the suite passes in a few seconds with every socket call blocked. So nothing is disabled or excluded here. The `integration` marker is registered anyway, and the job runs `-m "not integration"`, so the mechanism is live the moment a test does need a database — mirroring how WasteMAP splits backend/tests/fast from backend/tests/integration. --strict-markers keeps a mistyped marker from silently landing in the fast job. This complements WasteMAP's CI rather than replacing it. WasteMAP installs a SWEET_python branch with the same name as the WasteMAP branch under test, so a model change here and its consumer over there are already exercised as a pair. What that pairing never did was run this repo's own tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…rning checkout@v4 and setup-python@v5 both target Node 20, which the runners now force onto Node 24 with a deprecation annotation. v7 of each is the Node 24 build. The only other breaking change in between is checkout's safer `pull_request_target` default, and this workflow uses `pull_request`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
11 tasks
There was a problem hiding this comment.
🟢 Approval recommended
The workflow/config additions satisfy the stated CI goal, with only a minor documentation tweak suggested for reproducible local installs.
Pull request overview
This PR adds first-class CI coverage for SWEET_python’s existing pytest suite by introducing a GitHub Actions workflow that runs on every push and pull request, along with the minimal pytest configuration and contributor documentation needed to support it.
Changes:
- Add a GitHub Actions workflow to run
pytest -m "not integration"on Python 3.12 forpushandpull_request. - Add
pytest.inito scope test collection totests/and register theintegrationmarker with strict marker checking. - Document how to run tests locally and how to mark future integration tests in the README.
File summaries
| File | Description |
|---|---|
| README.md | Adds a “Tests” section describing local test execution and the fast/integration marker split. |
| pytest.ini | Configures pytest collection (testpaths) and enables --strict-markers with an integration marker registration. |
| .github/workflows/tests.yml | Introduces CI to install deps and run fast pytest on pushes and PRs using Python 3.12. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
10 tasks
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Output
SWEET_python's
tests/directory gets run by CI. It has held 8 test files and noworkflow that runs them;
.github/workflows/contained onlyjira_ticket.yml.As a SWEET_python contributor, I want the test suite to run on every push
and pull request so that a model change that breaks an existing test is caught
here, in the repo that owns the code — and so that tests of this package's
internals can live here at all.
Why now
Because nothing gated them, model unit tests have been getting written in
WasteMAP's
backend/tests/fast/instead — the only repo of the pair with test CI.That forces WasteMAP's suite to import private SWEET_python helpers, e.g.
SWEET_python.advanced_dst_city._prevent_food_waste, which Copilot flagged onRMI/WasteMAP#772. With a test workflow here, those tests have somewhere better to
go.
I checked the existing tests before adding the gate
They are all fine. 133 tests, all passing on Python 3.12 against the pinned
lockfile — nothing stale, nothing disabled, nothing excluded:
test_dst_allocation.pytest_mcf.pytest_flare_slip_and_capture_bounds.pytest_mass_checker_integration.pytest_food_waste_prevention.pytest_model_v2_oxidation_emission_year.pytest_sdst_v1_5_preimplement_composition.pytest_model_v2_years.pyNone of them needs a database, network access or an environment variable. I
verified that rather than assuming it: with
socket.connect,connect_ex,getaddrinfoandcreate_connectionall replaced by a raising stub, the fullsuite still passes in 2.7s. Grepping the suite agrees — the only
pytest.markusage anywhere in
tests/isparametrize, and there is noskipif, noos.environ, and no DB driver import.So the fast/integration split this workflow sets up has nothing in its integration
half yet. That is the honest state of the repo, not a shortcut.
What the workflow does
pytest -m "not integration"on Python 3.12, onpushandpull_request.Roughly 50s end to end, of which the tests are 4s.
package actually executes. (The code needs 3.10+ for PEP 604 annotations, so
3.12 is a match to reality, not a floor this workflow invents.)
requirements.txt, which is what that lockfile says itexists for. It then installs the package itself with
--no-deps -e ., soimport SWEET_pythonresolves to the checkout andsetup.py's packaging getsexercised on the way.
libpq-devis installed becausepsycopg2(notpsycopg2-binary)publishes no manylinux wheel — pip builds it from source and needs
pg_config.Confirmed necessary: the CI log shows
Building wheel for psycopg2taking ~6s.>=8,<10): minor and patch releases arewelcome, a major one should not break CI on a day nobody touched the model.
pytest.iniregisters theintegrationmarker and setstestpaths = tests(so
dst_allocation_prototype.py, the ~400k-case fuzz harness at the repo root,is never collected) and
--strict-markers, so a mistyped@pytest.mark.integratonis a collection error instead of a test that silentlykeeps running in the fast job. All three behaviours are verified with a
throwaway probe test.
checkout@v7,setup-python@v7);v4/v5 target Node 20 and produce a deprecation annotation. Dependabot already
covers
github-actionshere, so they will stay current.This complements WasteMAP's CI, it does not replace it
WasteMAP's
tests.ymlinstalls a SWEET_python branch with the same name asthe WasteMAP branch under test, so a model change here and its WasteMAP consumer
are already exercised as a pair over there. What that pairing never did is run
this repo's own tests. That is the gap, and it is why the trigger is
[push, pull_request]rather than PR-only: a SWEET_python branch is routinelypushed to pair with a same-named WasteMAP branch before either has a PR, and those
pushes should be gated too. The cost is that a branch with an open PR in this repo
runs twice for the same commit — cheap for a 4-second suite, and easy to trim to
push: branches: [main]if the second check is unwelcome.Deliberately not here
changelog/tracks model and methodology change — everyexisting entry is model behaviour, flagged for output effects. A test runner
changes no output and tells a WasteMAP or Climate TRACE consumer nothing. Happy
to add a line if you read the convention more broadly.
collects nothing exits 5. The marker is live the moment one is written, and the
first one should get its own job rather than a database bolted onto this one.
package ever needs to support a range.
Follow-up (not in this PR)
The five
_prevent_food_wasteunit tests in WasteMAP'sbackend/tests/fast/test_advanced_dst_city_food_prevention.pyare now movablehere, which would let that private import be dropped. The reasoning for keeping it
for now is recorded in a comment above the import (WasteMAP commit 621f11f6);
that comment should be revisited once this merges.
Acceptance criteria
pytestonpushandpull_request.registered
integrationmarker; the exclusion, the opt-in and thestrict-marker error are all verified.
Definition of Done
Tests / Fast testsgreen on this branch)# Testssection)🤖 Generated with Claude Code