Skip to content

grass.gunittest: Add the module name as an exception note - #7689

Merged
wenzeslaus merged 1 commit into
OSGeo:mainfrom
wenzeslaus:gunittest-import-error-note
Jul 14, 2026
Merged

wenzeslaus merged 1 commit into
OSGeo:mainfrom
wenzeslaus:gunittest-import-error-note

Conversation

@wenzeslaus

@wenzeslaus wenzeslaus commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

Now, the test loader raises a new ImportError to say which module could not be imported, but its message uses e.message, which does not exist in Python 3. The handler therefore raises AttributeError instead of the intended error.

Add the module name as a note to the original error instead. From the Python documentation of BaseException.add_note(): "Add the string note to the exception's notes which appear in the standard traceback after the exception string."

The traceback then shows the import error and the module which could not be imported:

ModuleNotFoundError: No module named 'something'
Cannot import module named test_something in /path/to/testsuite

The error is not caught anywhere, so it reaches a traceback, which is where a note is shown. The handler is not reached now, because the try block does not import the test module.

Exception notes need Python 3.11, which is now the minimum version (discussed in #4032). This touches the same lines as #4032, so whichever is merged second needs a trivial conflict resolution.

The test loader raised a new ImportError to say which module could not be
imported. The message used e.message, which does not exist in Python 3, so
the handler raised AttributeError instead of the intended error.

Add the module name as a note to the original error instead. From the Python
documentation of BaseException.add_note(): "Add the string note to the
exception's notes which appear in the standard traceback after the exception
string." The traceback then shows both the import error and the module name.

Exception notes need Python 3.11, which is now the minimum version.
@github-actions github-actions Bot added Python Related code is in Python libraries labels Jul 14, 2026
@wenzeslaus
wenzeslaus enabled auto-merge (squash) July 14, 2026 07:10
@wenzeslaus
wenzeslaus merged commit be451c4 into OSGeo:main Jul 14, 2026
27 checks passed
@wenzeslaus
wenzeslaus deleted the gunittest-import-error-note branch July 14, 2026 08:27
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 14, 2026
echoix pushed a commit to wenzeslaus/grass that referenced this pull request Jul 14, 2026
The test loader raised a new ImportError to say which module could not be
imported. The message used e.message, which does not exist in Python 3, so
the handler raised AttributeError instead of the intended error.

Add the module name as a note to the original error instead. From the Python
documentation of BaseException.add_note(): Add the string note to the
exception's notes which appear in the standard traceback after the exception
string. The traceback then shows both the import error and the module name.

Exception notes need Python 3.11, which is now the minimum version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants