[GRASS-git] [OSGeo/grass] a9ec50: grass.script: Do not print stderr when not capture...

Vaclav Petras noreply at github.com
Wed Mar 9 10:26:00 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: a9ec508d76cffce4ba016f41a89c8b3c4e44407f
      https://github.com/OSGeo/grass/commit/a9ec508d76cffce4ba016f41a89c8b3c4e44407f
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2022-03-09 (Wed, 09 Mar 2022)

  Changed paths:
    M python/grass/script/core.py
    M python/grass/script/tests/grass_script_setup_test.py

  Log Message:
  -----------
  grass.script: Do not print stderr when not captured (#2246)

Even when the global _capture_stderr is set, the functions allow users to not capture stderr (e.g., by using devnull). In these cases, sys.stderr.write fails because stderr is None. An example is grass.script.db.db_connection where db.connect regularly fails during grass.script.setup.finish when there is no database connection. With this fix, the function no longer fails and correctly handles the error state with except CalledModuleError.

The issue with the original code is visible in the code itself: _capture_stderr is used in a condition to set stderr=PIPE, but that's conditional on values in kwargs. However, this second condition is not considered when output stderr value is used later on.

The test function named test_init_finish_global_functions_capture_strerr fails with the previous version of the code.




More information about the grass-commit mailing list