contributing: Add a testing guide section for C functions - #7922
Open
Pranav-error wants to merge 1 commit into
Open
Pranav-error wants to merge 1 commit into
Pranav-error wants to merge 1 commit into
Conversation
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
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.
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.libcalls run inside the pytest process, so aG_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.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.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.gunittestis 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: thelib_vector_rtree_ctypes_test.pyexample still exists,Vect_new_cat_listis still inlib/vector/Vlib/cats.c, andxy_dataset_sessionis still a fixture.Rebased onto current
mainbefore opening; it had been sitting on the branch waiting for an open-PR slot to free.