diff --git a/Lib/test/test_gdb/util.py b/Lib/test/test_gdb/util.py index 29c7e9ee8f05498..ffe92137d844b71 100644 --- a/Lib/test/test_gdb/util.py +++ b/Lib/test/test_gdb/util.py @@ -11,9 +11,16 @@ GDB_PROGRAM = shutil.which('gdb') or 'gdb' +# First, try to use the build directory to support out-of-tree build +for key in ('abs_builddir', 'abs_srcdir', 'srcdir'): + SRC_DIR = sysconfig.get_config_var(key) + if SRC_DIR: + break +else: + raise Exception("unable to get the Python source directory") + # Location of custom hooks file in a repository checkout. -CHECKOUT_HOOK_PATH = os.path.join(os.path.dirname(sys.executable), - 'python-gdb.py') +CHECKOUT_HOOK_PATH = os.path.join(SRC_DIR, 'python-gdb.py') SAMPLE_SCRIPT = os.path.join(os.path.dirname(__file__), 'gdb_sample.py') BREAKPOINT_FN = 'builtin_id' diff --git a/Misc/NEWS.d/next/Tests/2026-11-06-23-15-23.gh-issue-161517.LkAlDt.rst b/Misc/NEWS.d/next/Tests/2026-11-06-23-15-23.gh-issue-161517.LkAlDt.rst new file mode 100644 index 000000000000000..fc76d235d207f0e --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-11-06-23-15-23.gh-issue-161517.LkAlDt.rst @@ -0,0 +1,3 @@ +Fix test_gdb when Python is built out-of-tree and Python is run from a +virtual environment. Previously, test_gdb was just skipped. Patch by Victor +Stinner.