Skip to content

pytest runs in CI on every push and pull request - #61

Merged
HughRunyan merged 2 commits into
mainfrom
pytest-runs-in-ci
Sep 9, 2026
Merged

pytest runs in CI on every push and pull request#61
HughRunyan merged 2 commits into
mainfrom
pytest-runs-in-ci

Conversation

@HughRunyan

Copy link
Copy Markdown
Collaborator

Output

SWEET_python's tests/ directory gets run by CI. It has held 8 test files and no
workflow that runs them; .github/workflows/ contained only jira_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 on
RMI/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:

File Tests
test_dst_allocation.py 58 pass
test_mcf.py 22 pass
test_flare_slip_and_capture_bounds.py 19 pass
test_mass_checker_integration.py 18 pass
test_food_waste_prevention.py 8 pass
test_model_v2_oxidation_emission_year.py 3 pass
test_sdst_v1_5_preimplement_composition.py 3 pass
test_model_v2_years.py 2 pass

None of them needs a database, network access or an environment variable. I
verified that rather than assuming it: with socket.connect, connect_ex,
getaddrinfo and create_connection all replaced by a raising stub, the full
suite still passes in 2.7s. Grepping the suite agrees — the only pytest.mark
usage anywhere in tests/ is parametrize, and there is no skipif, no
os.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, on push and pull_request.
Roughly 50s end to end, of which the tests are 4s.

  • Python 3.12 matches WasteMAP's CI and deploy images, which is where this
    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.)
  • Installs the pinned requirements.txt, which is what that lockfile says it
    exists for. It then installs the package itself with --no-deps -e ., so
    import SWEET_python resolves to the checkout and setup.py's packaging gets
    exercised on the way.
  • libpq-dev is installed because psycopg2 (not psycopg2-binary)
    publishes no manylinux wheel — pip builds it from source and needs pg_config.
    Confirmed necessary: the CI log shows Building wheel for psycopg2 taking ~6s.
  • pytest is bounded, not pinned (>=8,<10): minor and patch releases are
    welcome, a major one should not break CI on a day nobody touched the model.
  • pytest.ini registers the integration marker and sets testpaths = 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.integraton is a collection error instead of a test that silently
    keeps running in the fast job. All three behaviours are verified with a
    throwaway probe test.
  • Action versions are the current majors (checkout@v7, setup-python@v7);
    v4/v5 target Node 20 and produce a deprecation annotation. Dependabot already
    covers github-actions here, so they will stay current.

This complements WasteMAP's CI, it does not replace it

WasteMAP's tests.yml installs a SWEET_python branch with the same name as
the 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 routinely
pushed 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

  • No changelog entry. changelog/ tracks model and methodology change — every
    existing 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.
  • No integration job. There are no integration tests to put in it; a job that
    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.
  • No Python matrix. 3.12 is what ships. A matrix is cheap to add later if this
    package ever needs to support a range.

Follow-up (not in this PR)

The five _prevent_food_waste unit tests in WasteMAP's
backend/tests/fast/test_advanced_dst_city_food_prevention.py are now movable
here, 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

  • A GitHub Actions workflow runs pytest on push and pull_request.
  • It runs on Python 3.12.
  • Every existing test is accounted for: 133 pass, none disabled, none skipped.
  • Tests needing a database or network are excluded from the fast job by a
    registered integration marker; the exclusion, the opt-in and the
    strict-marker error are all verified.
  • The workflow is green on this branch.
  • Contributor docs say how to run the suite and where an integration test goes.

Definition of Done

  • Acceptance criteria met
  • Tests and checks pass (Tests / Fast tests green on this branch)
  • Docs updated (README gains a # Tests section)
  • Reviewed and merged

🤖 Generated with Claude Code

HughRunyan and others added 2 commits September 8, 2026 14:47
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>
@HughRunyan HughRunyan added documentation Improvements or additions to documentation test Adds or modifies tests ci Continuous integration / workflow changes labels Sep 8, 2026
@HughRunyan
HughRunyan requested a lite review from Copilot September 8, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 for push and pull_request.
  • Add pytest.ini to scope test collection to tests/ and register the integration marker 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.

Comment thread README.md
@HughRunyan
HughRunyan merged commit b5fcc4d into main Sep 9, 2026
3 checks passed
@HughRunyan
HughRunyan deleted the pytest-runs-in-ci branch September 9, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous integration / workflow changes documentation Improvements or additions to documentation test Adds or modifies tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants