Skip to content

contributing: Add a testing guide section for C functions - #7922

Open
Pranav-error wants to merge 1 commit into
OSGeo:mainfrom
Pranav-error:docs-testing-guide-c-functions
Open

Pranav-error wants to merge 1 commit into
OSGeo:mainfrom
Pranav-error:docs-testing-guide-c-functions

Conversation

@Pranav-error

Copy link
Copy Markdown
Contributor

Fixes #7862.

Adds a "Tests which call C functions" section to doc/development/testing.md, after "Tests which run in parallel".

@wenzeslaus opened the issue from a comment I made on #7851, so this is the write-up of that. It covers why the process matters and not only the mechanics:

  • grass.lib calls run inside the pytest process, so a G_fatal_error() or a segmentation fault takes the interpreter with it. pytest reports nothing — an exit code, no traceback, no captured output. That is what lib/vector: Fix null pointer dereference for an empty cat_list #7835 did to Windows CI: the run stopped at 8% and read as an infrastructure problem, and it was restarted twice before anyone traced it to one test.
  • In-process ctypes calls are fine when the function cannot abort, as in lib/vector/rtree/tests/lib_vector_rtree_ctypes_test.py, where the R-tree is a pure in-memory structure. The section says so rather than telling people to subprocess everything.
  • When the behaviour under test is a crash, run it through subprocess.run([sys.executable, "-c", SCRIPT], env=..., capture_output=True) and assert on the return code. The crash then arrives as one ordinary test failure that names the test, and the rest of the suite still runs.
  • grass.gunittest is not affected, since it already runs each test file as a subprocess. Worth saying, because it makes gunittest the more robust choice for C code expected to crash while pytest stays the better fit for small individual functions.

This is the narrow version you and I discussed on the issue. The wider "review all the techniques" part is deliberately not attempted here.

Docs only — no code changes. Every reference in the section is checked against current main: the lib_vector_rtree_ctypes_test.py example still exists, Vect_new_cat_list is still in lib/vector/Vlib/cats.c, and xy_dataset_session is still a fixture.

Rebased onto current main before opening; it had been sitting on the branch waiting for an open-PR slot to free.

A ctypes call runs in the pytest process, so C code which aborts ends the
whole run rather than one test: no traceback, no captured output, just an
exit code. Document running such calls in a subprocess, when it is needed
and when it is not, and note that grass.gunittest already subprocesses
each test file and is therefore unaffected.

Addresses OSGeo#7862
Copilot AI lite review requested due to automatic review settings September 17, 2026 19:42

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added docs markdown Related to markdown, markdown files labels Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs markdown Related to markdown, markdown files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Add a testing guide sec for C functions

2 participants