From fe167d3b4f78dec788fb53049416811ca2bf421f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 7 Nov 2026 01:23:58 +0100 Subject: [PATCH] gh-161517: Fix test_gdb on GHA Hypothesis tests (GH-161519) Fix test_gdb when Python is built out-of-tree and Python is run from a virtual environment. Previously, test_gdb was just skipped. Fix CHECKOUT_HOOK_PATH in test_gdb.util: get python-gdb.py from the build directory, rather than using the sys.executable directory. (cherry picked from commit ce4ac8c0459eba99459f03824cf1ac195c1aa7a1) Co-authored-by: Victor Stinner --- Lib/test/test_gdb/util.py | 11 +++++++++-- .../2026-11-06-23-15-23.gh-issue-161517.LkAlDt.rst | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2026-11-06-23-15-23.gh-issue-161517.LkAlDt.rst 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.