contributing: Add a testing guide - #7851
Conversation
The most complete statement of GRASS testing conventions lived in AGENTS.md, written for AI agents, and a contributor following the documented path never saw it. style_guide.md had no testing section, testsuite/README.md gave pytest a single sentence, and the Testing section in development_intro.md linked only the gunittest manual. This adds testing.md covering the choice between pytest and gunittest, test placement and naming, session fixtures, grass.tools, test data, running the tests, and tests which cannot run in parallel. AGENTS.md now points at the guide and keeps only its agent-specific notes, so the two cannot drift too much. This change was drafted with the help of Claude Code (Fable 5).
|
This branch is in the main repo, not my fork. I made a new clone and forgot to check/finish my setup. Since it is already created, I'll leave it as is and delete it when this PR is closed. |
|
Very glad to see this — I hit two of these conventions the hard way in the last few weeks and had to reconstruct them from other tests. One case the guide does not cover, and it bit me on #7835: a test that calls into C through ctypes should make those calls in a subprocess. My regression test there called Running the ctypes calls in a subprocess ( Worth a short subsection if you agree — the failure mode gives you nothing to go on, so it is hard to work out from first principles. Happy to draft the wording. |
|
@Pranav-error The C function tests are missing and you are right that it is a important gap to close. I would like to do it later in a separate PR which may include changes to existing tests. You can remind I promised that if I don't follow up on it in the future. |
testsuite/README.md described which testing frameworks exist and how to run pytest, which testing.md now covers, and the export commands in its Running tests section had stray backslashes which made them set literal strings when copied. The directory still needs a README: it is not in the Makefile DIRS list, is only a TODO in CMakeLists.txt, and holds raster_md5test.sh, which nothing else in the repository mentions. This keeps what the directory is for and the pointer to the CI, names raster_md5test.sh, and links testing.md for everything else. The North Carolina sample dataset URL moves to testing.md, next to the command which uses the dataset. This change was drafted with the help of Claude Code (Fable 5).
…, but linking other files is suficient. This solves both the duplication and the backslash issues. It also makes the sample dataset URL more readily available.
|
@Pranav-error I created an issue for you comment about C (and did not assign myself yet): #7862 |
The most complete statement of GRASS testing conventions lived in AGENTS.md, written for AI agents, and a contributor following the documented path never saw it. style_guide.md had no testing section, testsuite/README.md gave pytest a single sentence, and the Testing section in development_intro.md linked only the gunittest manual.
This adds testing.md covering the choice between pytest and gunittest, test placement and naming, session fixtures, grass.tools, test data, running the tests, and tests which cannot run in parallel. AGENTS.md now points at the guide and keeps only its agent-specific notes, so the two cannot drift too much.
This change was drafted with the help of Claude Code (Fable 5).
Details (AI-generated)
What the guide covers
Choosing between pytest and gunittest; where test files go and how they are named; setting up a session fixture; running tools with
grass.tools; generating test data; running the tests; andneeds_solo_run, which is load-bearing because CI's default pass runs--numprocesses=auto -m 'not needs_solo_run'and was documented nowhere.The conventions come from test code in the tree rather than from prose. Where the tree and
AGENTS.mddisagreed, the tree won.The gunittest command was wrong
grass -c <project>/<mapset> --exec ./test_x.pyfails withPermission denied. The test files are not executable (311 of 317 are mode 644, and only 13 have a shebang), andlib/init/grass.pyonly recovers fromENOENT, notEACCES. Separately, the-cform aborts on a second run because the mapset already exists, which is exactly the case of re-running a test after a fix.Both
testing.mdandAGENTS.mdnow use--tmp-mapsetwith an explicitpythoninterpreter, and note that some tests load data files by relative path and so must be run from their own directory.Reachability and the build
Linked from
CONTRIBUTING.md,doc/development/README.md,testsuite/README.md, a new short Testing section instyle_guide.md, andman/mkdocs/docs/development_intro.md. Registered indoc/development/Makefileanddoc/development/CMakeLists.txt, the same two placesstyle_guide.mdis registered; without both, the page builds nowhere and the link fromdevelopment_intro.md404s.Like the other development guides, the page is reached through
development_intro.mdrather than through the mkdocsnav. That is existing behaviour, not something this PR changes.style_guide.md
Gains a short Testing section stating the expectation and pointing at the guide. It asks that a bug fix touching untested code also add a test for that code's basic functionality, so it is visible that the fix did not break behaviour which was already correct.
Verification
r_slope_aspect_test.py, which also passes.AGENTS.mdand executed: exit 0, and again on a second consecutive run. A separate run reportedRan 16 testsandOK.-cform was executed and reproduced both failures.testing.htmlis generated and that the link fromdevelopment_intro.htmlresolves. This built against an existing dist tree with the new page added, not from a full build of this branch.gersemicould not run in this environment because its cache directory was not writable, so the one-lineCMakeLists.txtchange is unverified by that hook.Left for separate changes
testsuite/README.mdlines 25-26 contain literal backslashes in the export commands, so copying them sets literal strings instead of running the command substitutions.python/grass/grassdb/tests/grass_grassdb_create_xy.pymatches no collection pattern inpyproject.tomland is therefore never run, despite containing a test function.