https://github.com/python/cpython/commit/2eb95375092149634bdc34978c4030a0e0b4b033
commit: 2eb95375092149634bdc34978c4030a0e0b4b033
branch: main
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2025-12-14T03:31:42Z
summary:

gh-142368: Fix race comparing locations in test_external_inspection (#142691)

files:
M Lib/test/test_external_inspection.py

diff --git a/Lib/test/test_external_inspection.py 
b/Lib/test/test_external_inspection.py
index 4f3beb15f53b33..4ebd8aeeb89e7e 100644
--- a/Lib/test/test_external_inspection.py
+++ b/Lib/test/test_external_inspection.py
@@ -3183,10 +3183,31 @@ def level1():
         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(

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to