Skip to content

Commit 5eb5126

Browse files
authored
tests: harden 'extra table' cleanup vs. 403 (#362)
Closes #358.
1 parent c8dbb5d commit 5eb5126

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/sqlalchemy-bigquery/tests/system/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import pytest
2424
import sqlalchemy
2525

26+
from google.api_core import exceptions
2627
from google.cloud import bigquery
2728
import test_utils.prefixer
29+
import test_utils.retry
2830

2931
from sqlalchemy_bigquery import BigQueryDialect
3032

@@ -128,7 +130,10 @@ def bigquery_regional_dataset(bigquery_client, bigquery_schema):
128130
@pytest.fixture(autouse=True)
129131
def cleanup_extra_tables(bigquery_client, bigquery_dataset):
130132
common = "sample", "sample_one_row", "sample_view", "sample_dml_empty"
131-
for table in bigquery_client.list_tables(bigquery_dataset):
133+
# Back-end may raise 403 for a dataset not ready yet.
134+
retry_403 = test_utils.retry.RetryErrors(exceptions.Forbidden)
135+
tables = retry_403(bigquery_client.list_tables)(bigquery_dataset)
136+
for table in tables:
132137
if table.table_id not in common:
133138
bigquery_client.delete_table(table)
134139

0 commit comments

Comments
 (0)