Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit ab5df16

Browse files
author
Jim Fulton
authored
chore: Make it practical to make simultaneous compliance test runs. (#166)
1 parent f5adfc0 commit ab5df16

5 files changed

Lines changed: 36 additions & 24 deletions

File tree

noxfile.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,10 @@ def compliance(session):
212212
f"--junitxml=compliance_{session.python}_sponge_log.xml",
213213
"--reruns=3",
214214
"--reruns-delay=60",
215-
"--only-rerun="
216-
"403 Exceeded rate limits|"
217-
"409 Already Exists|"
218-
"404 Not found|"
219-
"400 Cannot execute DML over a non-existent table",
215+
"--only-rerun=403 Exceeded rate limits",
216+
"--only-rerun=409 Already Exists",
217+
"--only-rerun=404 Not found",
218+
"--only-rerun=400 Cannot execute DML over a non-existent table",
220219
system_test_folder_path,
221220
*session.posargs,
222221
)

pybigquery/requirements.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def schemas(self):
134134
"""Target database must support external schemas, and have one
135135
named 'test_schema'."""
136136

137-
return supported()
137+
return unsupported()
138138

139139
@property
140140
def implicit_default_schema(self):
@@ -218,3 +218,15 @@ def order_by_label_with_expression(self):
218218
219219
"""
220220
return supported()
221+
222+
223+
class WithSchemas(Requirements):
224+
"""
225+
Option to run without schema tests
226+
227+
because the `test_schema` name can't be overridden.
228+
"""
229+
230+
@property
231+
def schemas(self):
232+
return supported()

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ universal = 1
2222
requirement_cls=pybigquery.requirements:Requirements
2323
profile_file=sqlalchemy_dialect_compliance-profiles.txt
2424

25-
[db]
26-
default=bigquery:///test_pybigquery_sqla
27-
2825
[tool:pytest]
2926
addopts= --tb native -v -r fxX -p no:warnings
3027
python_files=tests/*test_*.py

tests/sqlalchemy_dialect_compliance/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
==================================
12
SQLAlchemy Dialog Compliance Tests
23
==================================
34

tests/sqlalchemy_dialect_compliance/conftest.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@
1717
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1818
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1919

20+
import contextlib
21+
import random
22+
import traceback
23+
24+
import sqlalchemy
25+
from sqlalchemy.testing import config
2026
from sqlalchemy.testing.plugin.pytestplugin import * # noqa
2127
from sqlalchemy.testing.plugin.pytestplugin import (
2228
pytest_sessionstart as _pytest_sessionstart,
29+
pytest_sessionfinish as _pytest_sessionfinish,
2330
)
2431

2532
import google.cloud.bigquery.dbapi.connection
2633
import pybigquery.sqlalchemy_bigquery
27-
import sqlalchemy
28-
import traceback
2934

3035
pybigquery.sqlalchemy_bigquery.BigQueryDialect.preexecute_autoincrement_sequences = True
3136
google.cloud.bigquery.dbapi.connection.Connection.rollback = lambda self: None
@@ -51,18 +56,16 @@ def visit_delete(self, delete_stmt, *args, **kw):
5156
pybigquery.sqlalchemy_bigquery.BigQueryCompiler.visit_delete = visit_delete
5257

5358

54-
# Clean up test schemas so we don't get spurious errors when the tests
55-
# try to create tables that already exist.
5659
def pytest_sessionstart(session):
57-
client = google.cloud.bigquery.Client()
58-
for schema in "test_schema", "test_pybigquery_sqla":
59-
for table_item in client.list_tables(f"{client.project}.{schema}"):
60-
table_id = table_item.table_id
61-
list(
62-
client.query(
63-
f"drop {'view' if table_id.endswith('_v') else 'table'}"
64-
f" {schema}.{table_id}"
65-
).result()
66-
)
67-
client.close()
60+
dataset_id = f"test_pybigquery_sqla{random.randint(0, 1<<63)}"
61+
session.config.option.dburi = [f"bigquery:///{dataset_id}"]
62+
with contextlib.closing(google.cloud.bigquery.Client()) as client:
63+
client.create_dataset(dataset_id)
6864
_pytest_sessionstart(session)
65+
66+
67+
def pytest_sessionfinish(session):
68+
dataset_id = config.db.dialect.dataset_id
69+
_pytest_sessionfinish(session)
70+
with contextlib.closing(google.cloud.bigquery.Client()) as client:
71+
client.delete_dataset(dataset_id, delete_contents=True)

0 commit comments

Comments
 (0)