[PATCH] [gdb/testsuite] Fix gdb.python/py-failed-init.exp with python 3.15

Tom de Vries <[email protected]> Wed, 5 Aug 2026 15:36:39 +0200
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
On Fedora Rawhide aarch64-linux, I ran into:
...
builtin_spawn $build/gdb/gdb -nw -nx -q -iex set height 0 -iex set width 0 \
  -data-directory $build/gdb/data-directory -iex set interactive-mode on
WARN: Could not find the standard library directory! The Python 'home'
directory was set to 'foo', is this correct?
Error occurred computing Python error message.
$build/gdb/gdb: warning:
Could not load the Python gdb module from
`$build/gdb/data-directory/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.
(gdb) set height 0
(gdb) set width 0
(gdb) dir
Reinitialize source path to empty? (y or n) y
Source directories searched: $cdir:$cwd
(gdb) dir $src/gdb/testsuite/gdb.python
Source directories searched:
$src/gdb/testsuite/gdb.python:$cdir:$cwd
(gdb) python print (1)
1
(gdb) FAIL: $exp: gdb-command<python print (1)>
quit
Exception ignored on threading shutdown:
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'importlib'
PASS: gdb.python/py-failed-init.exp: quit
...

The ModuleNotFoundError reported after quit originates from
gdbpy_initialize_gdb_readline.  I've filed a PR about this [1].

The test-case tries to break python:
...
save_vars { env(PYTHONHOME) } {
    setenv PYTHONHOME foo
    clean_restart
}
...
enough to get it to this point:
...
gdb_test "python print (1)" \
    "Python not initialized"
...
but apparently, that doesn't work anymore in this python version:
...
$ python --version
Python 3.15.0b4
...

Update the test-case by simply accepting the output.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=34485
---
 gdb/testsuite/gdb.python/py-failed-init.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.python/py-failed-init.exp b/gdb/testsuite/gdb.python/py-failed-init.exp
index 622743d8d9b..64583df6a96 100644
--- a/gdb/testsuite/gdb.python/py-failed-init.exp
+++ b/gdb/testsuite/gdb.python/py-failed-init.exp
@@ -22,7 +22,7 @@ save_vars { env(PYTHONHOME) } {
 }
 
 gdb_test "python print (1)" \
-    "Python not initialized"
+    "(Python not initialized|1)"
 
 gdb_test_multiple "quit" "" {
     eof {

base-commit: b7da195b94b423e5cfd27a14c636ffe9f7380cdd
-- 
2.51.0