Skip to content

Commit

Permalink
tests: harden 'extra table' cleanup vs. 403 (#362)
Browse files Browse the repository at this point in the history
Closes #358.
  • Loading branch information
tseaver committed Oct 26, 2021
1 parent 1ce4e14 commit 7f1ce80
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/system/conftest.py
Expand Up @@ -23,8 +23,10 @@
import pytest
import sqlalchemy

from google.api_core import exceptions
from google.cloud import bigquery
import test_utils.prefixer
import test_utils.retry

from sqlalchemy_bigquery import BigQueryDialect

Expand Down Expand Up @@ -128,7 +130,10 @@ def bigquery_regional_dataset(bigquery_client, bigquery_schema):
@pytest.fixture(autouse=True)
def cleanup_extra_tables(bigquery_client, bigquery_dataset):
common = "sample", "sample_one_row", "sample_view", "sample_dml_empty"
for table in bigquery_client.list_tables(bigquery_dataset):
# Back-end may raise 403 for a dataset not ready yet.
retry_403 = test_utils.retry.RetryErrors(exceptions.Forbidden)
tables = retry_403(bigquery_client.list_tables)(bigquery_dataset)
for table in tables:
if table.table_id not in common:
bigquery_client.delete_table(table)

Expand Down

0 comments on commit 7f1ce80

Please sign in to comment.