@@ -253,8 +253,13 @@ def _execute_sql_helper(
253253 ]
254254 for i in range (len (result_sets )):
255255 result_sets [i ].values .extend (VALUE_PBS [i ])
256- iterator = _MockIterator (* result_sets )
257- api .execute_streaming_sql .return_value = iterator
256+
257+ def _make_iterator (* args , ** kwargs ):
258+ from copy import deepcopy
259+
260+ return _MockIterator (* deepcopy (result_sets ))
261+
262+ api .execute_streaming_sql .side_effect = _make_iterator
258263 transaction ._execute_sql_request_count = sql_count
259264 transaction ._read_request_count = count
260265
@@ -360,7 +365,12 @@ def _read_helper(
360365 for i in range (len (result_sets )):
361366 result_sets [i ].values .extend (VALUE_PBS [i ])
362367
363- api .streaming_read .return_value = _MockIterator (* result_sets )
368+ def _make_iterator (* args , ** kwargs ):
369+ from copy import deepcopy
370+
371+ return _MockIterator (* deepcopy (result_sets ))
372+
373+ api .streaming_read .side_effect = _make_iterator
364374 transaction ._read_request_count = count
365375
366376 if partition is not None : # 'limit' and 'partition' incompatible
@@ -957,9 +967,6 @@ def test_transaction_should_use_transaction_id_returned_by_first_batch_update(se
957967 timeout = TIMEOUT ,
958968 )
959969
960- @pytest .mark .skip (
961- reason = "Inherently flaky, relies on thread crash swallowing in older Pytest"
962- )
963970 def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_execute_update (
964971 self ,
965972 ):
@@ -1033,9 +1040,6 @@ def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_
10331040 self .assertEqual (api .execute_sql .call_count , 2 )
10341041 self .assertEqual (api .execute_batch_dml .call_count , 1 )
10351042
1036- @pytest .mark .skip (
1037- reason = "Inherently flaky, relies on thread crash swallowing in older Pytest"
1038- )
10391043 def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_batch_update (
10401044 self ,
10411045 ):
@@ -1103,7 +1107,7 @@ def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_
11031107 self .assertEqual (actual_id_suffixes , expected_id_suffixes )
11041108
11051109 @pytest .mark .skip (
1106- reason = "Inherently flaky, relies on thread crash swallowing in older Pytest "
1110+ reason = "Inherently flaky: concurrent StreamedResultSet requests race inline begins due to lazy evaluation "
11071111 )
11081112 def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_read (
11091113 self ,
@@ -1179,7 +1183,7 @@ def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_
11791183 self .assertEqual (actual_id_suffixes , expected_id_suffixes )
11801184
11811185 @pytest .mark .skip (
1182- reason = "Inherently flaky, relies on thread crash swallowing in older Pytest "
1186+ reason = "Inherently flaky: concurrent StreamedResultSet requests race inline begins due to lazy evaluation "
11831187 )
11841188 def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_query (
11851189 self ,
0 commit comments