Skip to content

Commit 09099e9

Browse files
authored
test: deflake autocommit sample test (#255)
* test: deflake autocommit sample test * test: fix DDL call Co-authored-by: larkee <[email protected]>
1 parent 215aaae commit 09099e9

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

samples/samples/autocommit_test.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
from google.api_core.exceptions import Aborted
1010
from google.cloud import spanner
11-
from google.cloud.spanner_dbapi import connect
12-
import mock
1311
import pytest
1412
from test_utils.retry import RetryErrors
1513

@@ -53,13 +51,13 @@ def database(spanner_instance):
5351

5452
@RetryErrors(exception=Aborted, max_tries=2)
5553
def test_enable_autocommit_mode(capsys, database):
56-
connection = connect(INSTANCE_ID, DATABASE_ID)
57-
cursor = connection.cursor()
58-
59-
with mock.patch(
60-
"google.cloud.spanner_dbapi.connection.Cursor", return_value=cursor,
61-
):
62-
autocommit.enable_autocommit_mode(INSTANCE_ID, DATABASE_ID)
63-
out, _ = capsys.readouterr()
64-
assert "Autocommit mode is enabled." in out
65-
assert "SingerId: 13, AlbumId: Russell, AlbumTitle: Morales" in out
54+
# Delete table if it exists for retry attempts.
55+
table = database.table('Singers')
56+
if table.exists():
57+
op = database.update_ddl(["DROP TABLE Singers"])
58+
op.result()
59+
60+
autocommit.enable_autocommit_mode(INSTANCE_ID, DATABASE_ID)
61+
out, _ = capsys.readouterr()
62+
assert "Autocommit mode is enabled." in out
63+
assert "SingerId: 13, AlbumId: Russell, AlbumTitle: Morales" in out

0 commit comments

Comments
 (0)