Add a lightweight pytest harness for pure helper functions#12
Open
mklarmann wants to merge 1 commit into
Open
Conversation
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
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.
Introduces a minimal test setup so SALCA's self-contained helper functions can be unit-tested without the SALCAfuture database.
Because the modules import
salcaconnectorand build a database context at import time, they can't be imported directly.tests/conftest.pyworks around this by extracting a single top-level function from a module's source viaastand executing only that definition — no module-level DB setup is triggered.Included:
tests/conftest.py— theload_functionhelpertests/test_pure_functions.py— regression tests forc_month(SALCAnitrate) andwaterRegimeCode(SALCAphosphor)pytest.ini,requirements-dev.txt,tests/README.mdAssertions that depend on still-open bug-fix PRs (#3, #6) are marked
xfailand reference the issues, so the suite is green onmain(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.