[GRASS-git] [OSGeo/grass] 2bd2d0: tests: Use string and subprocess for isolation (#6...

Vaclav Petras noreply at github.com
Thu Oct 16 14:00:40 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: 2bd2d0ae1d9fb6d99f0d3609ab1fb342209a8799
      https://github.com/OSGeo/grass/commit/2bd2d0ae1d9fb6d99f0d3609ab1fb342209a8799
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2025-10-16 (Thu, 16 Oct 2025)

  Changed paths:
    M lib/gis/tests/lib_gis_env_test.py
    M python/grass/script/tests/conftest.py
    M python/grass/script/tests/grass_script_core_location_test.py
    M python/grass/script/tests/grass_script_setup_test.py

  Log Message:
  -----------
  tests: Use string and subprocess for isolation (#6514)

Instead of using multiprocessing, use code in a string and subprocess with sys.executable to run code in isolation. While this is requires the tested code to be in a string as opposed to a function, this avoids many issues of multiprocessing (stuck queue on failure, complexities of spawning). It replaces queue communication with JSON in stdout which requires additional care in what is actually printed.

As a result, the global environment is clearly not changed (it is a subprocess) as opposed to relying on multiprocessing behavior. For C library test, the separation of processes is even more clear, while at the same time, the test itself can now set up the runtime environment for dynamic libraries instead of relying on the external environment.

Renames and document tests in grass_script_setup_test.py with their current scope as their scope shifted when only one way of isolating and calling is used (no more partial vs nested function). Clarify role of setting the global capturing stderr in the tests and add more capture stderr smoke testing.

Be more consistent in mocking no global session with the fixture.

Uses capture outputs and exception to report stderr from the subprocess to ensure it is reported instead of relying on stderr being printed through pytest (stderr does not show up on Windows in CI with pytest for failures in lib_gis_env_test.py).

The constructed script needs to use raw strings for the path to accommodate backslashes (as a way of dealing with Windows paths).

The library test is skipped on Windows because the environment is not refreshed with the changes made in Python. Python updates it, but the getter function on Windows apparently keeps using a cached version, so the C functions access with ctypes don't see GISRC and fail with no session.



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass/settings/notifications


More information about the grass-commit mailing list