Skip to content

test_gdb are not skipped properly if gdb is not available (instead, an uncaught exception is raised) #110995

Closed
@befeleme

Description

@befeleme

Bug report

Bug description:

I'm bootstrapping Python 3.13a1 in Fedora Linux.
In my environment I've got gdb built without Python. Now I want to build full Python and run its tests during the RPM build.

What happens
Tests from package test_gdb fail due to uncaught exception.

What should happen
Tests should be marked as skipped and not executed at all.

Traceback

0:28:25 load avg: 2.73 Re-running 5 failed tests in verbose mode in subprocesses
0:28:25 load avg: 2.73 Run 5 tests in parallel using 2 worker processes (timeout: 45 min, worker timeout: 50 min)
0:28:26 load avg: 2.73 [1/5/1] test.test_gdb.test_cfunction failed (uncaught exception)
Re-running test.test_gdb.test_cfunction in verbose mode
test test.test_gdb.test_cfunction crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_cfunction.py", line 5, in 
    from .util import setup_module, DebuggerTests
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:26 load avg: 2.73 [2/5/2] test.test_gdb.test_backtrace failed (uncaught exception)
Re-running test.test_gdb.test_backtrace in verbose mode
test test.test_gdb.test_backtrace crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_backtrace.py", line 6, in 
    from .util import setup_module, DebuggerTests, CET_PROTECTION, SAMPLE_SCRIPT
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:27 load avg: 2.73 [3/5/3] test.test_gdb.test_cfunction_full failed (uncaught exception)
Re-running test.test_gdb.test_cfunction_full in verbose mode
test test.test_gdb.test_cfunction_full crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_cfunction_full.py", line 7, in 
    from .util import setup_module
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:27 load avg: 2.73 [4/5/4] test.test_gdb.test_misc failed (uncaught exception)
Re-running test.test_gdb.test_misc in verbose mode
test test.test_gdb.test_misc crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_misc.py", line 5, in 
    from .util import run_gdb, setup_module, DebuggerTests, SAMPLE_SCRIPT
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:27 load avg: 2.73 [5/5/5] test.test_gdb.test_pretty_print failed (uncaught exception)
Re-running test.test_gdb.test_pretty_print in verbose mode
test test.test_gdb.test_pretty_print crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_pretty_print.py", line 5, in 
    from .util import (
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
5 tests failed again:
    test.test_gdb.test_backtrace test.test_gdb.test_cfunction
    test.test_gdb.test_cfunction_full test.test_gdb.test_misc
    test.test_gdb.test_pretty_print

I believe the refactoring done in #110026 has introduced a regression. run_gdb() used to always return a tuple (stdout, stderr), but now it checks exitcode and raises an exception in case it's not what was expected. check_usable_gdb() consumes the values returned from run_gdb() and only then marks tests as skipped, but in this case the exception breaks the test run even before this can happen.

cc: @vstinner

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions