Skip to content

Add a lightweight pytest harness for pure helper functions#12

Open
mklarmann wants to merge 1 commit into
agroscope-ch:mainfrom
mklarmann:chore/add-test-harness
Open

Add a lightweight pytest harness for pure helper functions#12
mklarmann wants to merge 1 commit into
agroscope-ch:mainfrom
mklarmann:chore/add-test-harness

Conversation

@mklarmann

Copy link
Copy Markdown

Introduces a minimal test setup so SALCA's self-contained helper functions can be unit-tested without the SALCAfuture database.

Because the modules import salcaconnector and build a database context at import time, they can't be imported directly. tests/conftest.py works around this by extracting a single top-level function from a module's source via ast and executing only that definition — no module-level DB setup is triggered.

Included:

  • tests/conftest.py — the load_function helper
  • tests/test_pure_functions.py — regression tests for c_month (SALCAnitrate) and waterRegimeCode (SALCAphosphor)
  • pytest.ini, requirements-dev.txt, tests/README.md

Assertions that depend on still-open bug-fix PRs (#3, #6) are marked xfail and reference the issues, so the suite is green on main (1 passed, 3 xfailed) and the xfails will flip to passing once those fixes merge (at which point the markers can be removed).

This is intended as optional infrastructure — happy to adjust the style or scope to match your preferences.

Introduces a minimal test setup that can unit-test SALCA's self-contained helper
functions without the SALCAfuture database: conftest.load_function extracts a
single top-level function from a module's source via ast and runs only that
definition, avoiding the module-level database context creation.

Includes regression tests for c_month (SALCAnitrate) and waterRegimeCode
(SALCAphosphor). Assertions that depend on still-open bug-fix PRs are marked
xfail and reference the relevant issues, so the suite is green on main and the
xfails flip to passing once those fixes land.

Run with: pip install -r requirements-dev.txt && pytest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant