@@ -3183,10 +3183,31 @@ def level1():
31833183 funcs_no_cache = [f .funcname for f in frames_no_cache ]
31843184 self .assertEqual (funcs_cached , funcs_no_cache )
31853185
3186- # Same locations
3187- locations_cached = [f .location for f in frames_cached ]
3188- locations_no_cache = [f .location for f in frames_no_cache ]
3189- self .assertEqual (locations_cached , locations_no_cache )
3186+ # For level3 (leaf frame), due to timing races we can be at either
3187+ # sock.sendall() or sock.recv() - both are valid. For parent frames,
3188+ # the locations should match exactly.
3189+ # Valid locations for level3: line 3 has two statements
3190+ # sock.sendall(b"ready") -> col 4-26
3191+ # sock.recv(16) -> col 28-41
3192+ level3_valid_cols = {(4 , 26 ), (28 , 41 )}
3193+
3194+ for i in range (len (frames_cached )):
3195+ loc_cached = frames_cached [i ].location
3196+ loc_no_cache = frames_no_cache [i ].location
3197+
3198+ if frames_cached [i ].funcname == "level3" :
3199+ # Leaf frame: can be at either statement
3200+ self .assertIn (
3201+ (loc_cached .col_offset , loc_cached .end_col_offset ),
3202+ level3_valid_cols ,
3203+ )
3204+ self .assertIn (
3205+ (loc_no_cache .col_offset , loc_no_cache .end_col_offset ),
3206+ level3_valid_cols ,
3207+ )
3208+ else :
3209+ # Parent frames: must match exactly
3210+ self .assertEqual (loc_cached , loc_no_cache )
31903211
31913212 @skip_if_not_supported
31923213 @unittest .skipIf (
0 commit comments