From de93be55befeeaa247559010eb9d4ec4acca19f0 Mon Sep 17 00:00:00 2001 From: Nick Begg Date: Fri, 24 Apr 2026 00:19:27 +0200 Subject: [PATCH 1/2] Fix problem with symlink paths in unittest/loader.py --- Lib/unittest/loader.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py index a52950dad224ee..869e851c255c51 100644 --- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -356,7 +356,10 @@ def _get_name_from_path(self, path): return '.' path = _splitext(os.path.normpath(path)) - _relpath = os.path.relpath(path, self._top_level_dir) + path_real = os.path.realpath(path) + tld_real = os.path.realpath(self._top_level_dir) + _relpath = os.path.relpath(path_real, tld_real) + assert not os.path.isabs(_relpath), "Path must be within the project" assert not _relpath.startswith('..'), "Path must be within the project" From c3350d27f43aa32bff28eb34ba862c956b462532 Mon Sep 17 00:00:00 2001 From: Nick Begg Date: Wed, 29 Apr 2026 11:21:04 +0200 Subject: [PATCH 2/2] add blurb --- .../next/Tests/2026-04-29-11-20-43.gh-issue-149141.Ue1Qww.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2026-04-29-11-20-43.gh-issue-149141.Ue1Qww.rst diff --git a/Misc/NEWS.d/next/Tests/2026-04-29-11-20-43.gh-issue-149141.Ue1Qww.rst b/Misc/NEWS.d/next/Tests/2026-04-29-11-20-43.gh-issue-149141.Ue1Qww.rst new file mode 100644 index 00000000000000..9d57c46ee546cb --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-04-29-11-20-43.gh-issue-149141.Ue1Qww.rst @@ -0,0 +1,4 @@ +Test discovery would fail when the path to the source tree contains a +symlink. Paths that take an alternate route to the same place (eg just the +real path) would not be considered a subpath, and cause an assert. Instead, +always resolve to the real path before comparing.