]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-142368: Fix race comparing locations in test_external_inspection (#142691)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Sun, 14 Dec 2025 03:31:42 +0000 (03:31 +0000)
committerGitHub <noreply@github.com>
Sun, 14 Dec 2025 03:31:42 +0000 (03:31 +0000)
Lib/test/test_external_inspection.py

index 4f3beb15f53b33d2a4d2b528031f56f0d27084a2..4ebd8aeeb89e7e9ba8ba64fc5b33b6e43c9862de 100644 (file)
@@ -3183,10 +3183,31 @@ sock.connect(('localhost', {port}))
         funcs_no_cache = [f.funcname for f in frames_no_cache]
         self.assertEqual(funcs_cached, funcs_no_cache)
 
-        # Same locations
-        locations_cached = [f.location for f in frames_cached]
-        locations_no_cache = [f.location for f in frames_no_cache]
-        self.assertEqual(locations_cached, locations_no_cache)
+        # For level3 (leaf frame), due to timing races we can be at either
+        # sock.sendall() or sock.recv() - both are valid. For parent frames,
+        # the locations should match exactly.
+        # Valid locations for level3: line 3 has two statements
+        #   sock.sendall(b"ready") -> col 4-26
+        #   sock.recv(16) -> col 28-41
+        level3_valid_cols = {(4, 26), (28, 41)}
+
+        for i in range(len(frames_cached)):
+            loc_cached = frames_cached[i].location
+            loc_no_cache = frames_no_cache[i].location
+
+            if frames_cached[i].funcname == "level3":
+                # Leaf frame: can be at either statement
+                self.assertIn(
+                    (loc_cached.col_offset, loc_cached.end_col_offset),
+                    level3_valid_cols,
+                )
+                self.assertIn(
+                    (loc_no_cache.col_offset, loc_no_cache.end_col_offset),
+                    level3_valid_cols,
+                )
+            else:
+                # Parent frames: must match exactly
+                self.assertEqual(loc_cached, loc_no_cache)
 
     @skip_if_not_supported
     @unittest.skipIf(