@@ -655,8 +655,10 @@ def _create_mock_connection(self, mock_session_class):
655655 mock_session .get_autocommit .return_value = True
656656 mock_session_class .return_value = mock_session
657657
658- # Create connection
659- conn = client .Connection (** self .DUMMY_CONNECTION_ARGS )
658+ # Create connection with ignore_transactions=False to test actual transaction functionality
659+ conn = client .Connection (
660+ ignore_transactions = False , ** self .DUMMY_CONNECTION_ARGS
661+ )
660662 return conn
661663
662664 @patch ("%s.client.Session" % PACKAGE_NAME )
@@ -928,7 +930,9 @@ def test_fetch_autocommit_from_server_queries_server(self, mock_session_class):
928930 mock_session_class .return_value = mock_session
929931
930932 conn = client .Connection (
931- fetch_autocommit_from_server = True , ** self .DUMMY_CONNECTION_ARGS
933+ fetch_autocommit_from_server = True ,
934+ ignore_transactions = False ,
935+ ** self .DUMMY_CONNECTION_ARGS ,
932936 )
933937
934938 mock_cursor = Mock ()
@@ -958,7 +962,9 @@ def test_fetch_autocommit_from_server_handles_false_value(self, mock_session_cla
958962 mock_session_class .return_value = mock_session
959963
960964 conn = client .Connection (
961- fetch_autocommit_from_server = True , ** self .DUMMY_CONNECTION_ARGS
965+ fetch_autocommit_from_server = True ,
966+ ignore_transactions = False ,
967+ ** self .DUMMY_CONNECTION_ARGS ,
962968 )
963969
964970 mock_cursor = Mock ()
@@ -983,7 +989,9 @@ def test_fetch_autocommit_from_server_raises_on_no_result(self, mock_session_cla
983989 mock_session_class .return_value = mock_session
984990
985991 conn = client .Connection (
986- fetch_autocommit_from_server = True , ** self .DUMMY_CONNECTION_ARGS
992+ fetch_autocommit_from_server = True ,
993+ ignore_transactions = False ,
994+ ** self .DUMMY_CONNECTION_ARGS ,
987995 )
988996
989997 mock_cursor = Mock ()
@@ -998,6 +1006,90 @@ def test_fetch_autocommit_from_server_raises_on_no_result(self, mock_session_cla
9981006
9991007 conn .close ()
10001008
1009+ # ==================== IGNORE_TRANSACTIONS TESTS ====================
1010+
1011+ @patch ("%s.client.Session" % PACKAGE_NAME )
1012+ def test_commit_is_noop_when_ignore_transactions_true (self , mock_session_class ):
1013+ """Test that commit() is a no-op when ignore_transactions=True."""
1014+
1015+ mock_session = Mock ()
1016+ mock_session .is_open = True
1017+ mock_session .guid_hex = "test-session-id"
1018+ mock_session_class .return_value = mock_session
1019+
1020+ # Create connection with ignore_transactions=True (default)
1021+ conn = client .Connection (** self .DUMMY_CONNECTION_ARGS )
1022+
1023+ # Verify ignore_transactions is True by default
1024+ self .assertTrue (conn .ignore_transactions )
1025+
1026+ mock_cursor = Mock ()
1027+ with patch .object (conn , "cursor" , return_value = mock_cursor ):
1028+ # Call commit - should be no-op
1029+ conn .commit ()
1030+
1031+ # Verify that execute was NOT called (no-op)
1032+ mock_cursor .execute .assert_not_called ()
1033+ mock_cursor .close .assert_not_called ()
1034+
1035+ conn .close ()
1036+
1037+ @patch ("%s.client.Session" % PACKAGE_NAME )
1038+ def test_rollback_raises_not_supported_when_ignore_transactions_true (
1039+ self , mock_session_class
1040+ ):
1041+ """Test that rollback() raises NotSupportedError when ignore_transactions=True."""
1042+
1043+ mock_session = Mock ()
1044+ mock_session .is_open = True
1045+ mock_session .guid_hex = "test-session-id"
1046+ mock_session_class .return_value = mock_session
1047+
1048+ # Create connection with ignore_transactions=True (default)
1049+ conn = client .Connection (** self .DUMMY_CONNECTION_ARGS )
1050+
1051+ # Verify ignore_transactions is True by default
1052+ self .assertTrue (conn .ignore_transactions )
1053+
1054+ # Call rollback - should raise NotSupportedError
1055+ with self .assertRaises (NotSupportedError ) as ctx :
1056+ conn .rollback ()
1057+
1058+ self .assertIn ("Transactions are not supported" , str (ctx .exception ))
1059+
1060+ conn .close ()
1061+
1062+ @patch ("%s.client.Session" % PACKAGE_NAME )
1063+ def test_autocommit_setter_is_noop_when_ignore_transactions_true (
1064+ self , mock_session_class
1065+ ):
1066+ """Test that autocommit setter is a no-op when ignore_transactions=True."""
1067+
1068+ mock_session = Mock ()
1069+ mock_session .is_open = True
1070+ mock_session .guid_hex = "test-session-id"
1071+ mock_session_class .return_value = mock_session
1072+
1073+ # Create connection with ignore_transactions=True (default)
1074+ conn = client .Connection (** self .DUMMY_CONNECTION_ARGS )
1075+
1076+ # Verify ignore_transactions is True by default
1077+ self .assertTrue (conn .ignore_transactions )
1078+
1079+ mock_cursor = Mock ()
1080+ with patch .object (conn , "cursor" , return_value = mock_cursor ):
1081+ # Set autocommit - should be no-op
1082+ conn .autocommit = False
1083+
1084+ # Verify that execute was NOT called (no-op)
1085+ mock_cursor .execute .assert_not_called ()
1086+ mock_cursor .close .assert_not_called ()
1087+
1088+ # Session set_autocommit should also not be called
1089+ conn .session .set_autocommit .assert_not_called ()
1090+
1091+ conn .close ()
1092+
10011093
10021094if __name__ == "__main__" :
10031095 suite = unittest .TestLoader ().loadTestsFromModule (sys .modules [__name__ ])
0 commit comments