Model/backend/export
Khalim Conn-Kowlessar c1c7b06f09 refactor(modelling): consolidate plan/recommendation models into infrastructure
Move the live plan, recommendation, recommendation_materials and (retiring)
plan_recommendations tables into a new infrastructure/postgres/modelling/
subpackage as single SQLModel definitions (the epc_property pattern), absorbing
the rebuild's partial PlanRow/RecommendationRow mirrors and carrying full
legacy column parity plus recommendation.plan_id. Out-of-cluster references are
plain indexed ints (mirror convention); the live FKs are owned by the Drizzle
schema. backend/app/db/models/recommendations.py becomes a re-export shim
(ScenarioModel/InstalledMeasure stay for a later slice).

Fix the export conftest to create SQLModel-first (so Base funding_package's FK
to the now-SQLModel plan resolves) and skip the redundant drop_all on its
function-scoped throwaway DB (the epc enum type is now shared across both
metadatas). Resolves the pre-existing dual-definition collision: the rebuild
and legacy export suites are now co-runnable. No behaviour change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 21:00:14 +00:00
..
property_scenarios minor exporting data 2026-04-30 09:58:24 +01:00
tests refactor(modelling): consolidate plan/recommendation models into infrastructure 2026-06-03 21:00:14 +00:00
README.md added postgres to docker & added to readme 2026-02-27 18:58:59 +00:00

🧪 Running Tests in PyCharm (macOS + pytest-postgresql)

Our test suite uses pytest and pytest-postgresql, which automatically spins up a temporary PostgreSQL instance.

On Linux (including GitHub Actions), PostgreSQL binaries are installed in standard system locations.
On macOS (Homebrew), they are not --- so PyCharm needs a small configuration tweak to locate pg_ctl.

This guide explains how to run and debug tests locally in PyCharm without modifying test code.


Prerequisites

Devcontainer

Postgres install is included in the devcontainer, so no additional setup is needed.

Running

make test

Will instigate the test suite, which will automatically start a temporary PostgreSQL instance.

Local MacOS

  1. Install PostgreSQL via Homebrew:
brew install postgresql
  1. Confirm pg_ctl exists:
which pg_ctl

Typical output:

/opt/homebrew/bin/pg_ctl

🚀 Running Tests in PyCharm

Step 1 --- Create a PyCharm pytest Run Configuration

  1. Open the test file.
  2. Click the green ▶ next to the test.
  3. Choose "Edit Run Configuration..."

You should see something like:

  • Target: backend/export/tests/test_export.py
  • Working directory: Project root (e.g.Model/)

Step 2 --- Add Required Override (macOS Only)

In the Run Configuration:

➜ "Additional Arguments"

Add:

--override-ini=postgresql_exec=/opt/homebrew/bin/pg_ctl

This tells pytest-postgresql where pg_ctl lives on macOS.

Without this, PyCharm may fail with:

ExecutableMissingException: Could not found pg_config executable

Step 3 --- Run or Debug

You can now:

  • Click ▶ Run\
  • Click 🐞 Debug\
  • Set breakpoints normally

The temporary PostgreSQL instance will start automatically.


🔍 Why This Is Needed

pytest-postgresql defaults to a Linux-style path:

/usr/lib/postgresql/<version>/bin/pg_ctl

That path exists on Ubuntu (CI), but not on macOS.

On macOS, Homebrew installs PostgreSQL in:

/opt/homebrew/bin/

The --override-ini flag safely overrides the executable path locally, without modifying:

  • test files\
  • conftest.py\
  • pytest.ini\
  • CI configuration

This ensures:

  • Tests still work in GitHub Actions\
  • Tests still work for Linux users\
  • macOS developers can debug in PyCharm\
  • No repository-specific hacks are required

🛠 Optional: Using a Local .env File

If you prefer not to hardcode the override in the run configuration:

  1. Create a local file:
<!-- -->
.env.local
  1. Add:
<!-- -->
PYTEST_ADDOPTS=--override-ini=postgresql_exec=/opt/homebrew/bin/pg_ctl
  1. In PyCharm:
    • Open the Run Configuration
    • Add .env.local under "Paths to .env files"

🧪 Running Tests via Terminal (Recommended for CI Parity)

For normal execution outside PyCharm:

make test

These already work without additional configuration.


🧠 Summary

Environment Works Without Override? Needs --override-ini?


GitHub Actions (Linux) Yes No Linux local Yes No macOS terminal (tox) Yes No macOS PyCharm debugger No Yes