Skip to content

Commit 472f80e

Browse files
authored
SNOW-610866 Add support for SQLAlchemy’s dialect tests (#305)
1 parent cd3c107 commit 472f80e

File tree

10 files changed

+595
-4
lines changed

10 files changed

+595
-4
lines changed

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ development =
7474
numpy
7575
pandas =
7676
snowflake-connector-python[pandas]<3.0.0
77+
78+
[sqla_testing]
79+
requirement_cls=snowflake.sqlalchemy.requirements:Requirements
80+
profile_file=tests/profiles.txt
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
3+
#
4+
5+
from sqlalchemy.testing import exclusions
6+
from sqlalchemy.testing.requirements import SuiteRequirements
7+
8+
# TODO: check through the requirement list to determine which should be turned on/off
9+
10+
11+
class Requirements(SuiteRequirements):
12+
@property
13+
def autocommit(self):
14+
return exclusions.open()
15+
16+
@property
17+
def ctes(self):
18+
return exclusions.open()
19+
20+
@property
21+
def ctes_on_dml(self):
22+
return exclusions.open()
23+
24+
@property
25+
def ctes_with_update_delete(self):
26+
return exclusions.open()
27+
28+
@property
29+
def delete_from(self):
30+
return exclusions.open()

tests/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
3+
#

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
from sqlalchemy import create_engine
1313

1414
import snowflake.connector
15-
from parameters import CONNECTION_PARAMETERS
1615
from snowflake.connector.compat import IS_WINDOWS
1716
from snowflake.sqlalchemy import URL, dialect
1817

18+
from .parameters import CONNECTION_PARAMETERS
19+
1920
CLOUD_PROVIDERS = {"aws", "azure", "gcp"}
2021
EXTERNAL_SKIP_TAGS = {"internal"}
2122
INTERNAL_SKIP_TAGS = {"external"}

tests/sqlalchemy_test_suite/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SQLAlchemy Compliance Tests
2+
3+
SQLAlchemy offers tests to test SQLAlchemy dialects work properly. This directory applies these tests
4+
to the Snowflake SQLAlchemy dialect.
5+
6+
**Please be aware that the test suites are not collected in pytest by default** -- the directory is ignored in `tox.ini`.
7+
There are majorly three issues with the sqlalchemy test suites:
8+
1. Importing sqlalchemy pytest plugin will result in Snowflake SQLAlchemy dialect specific tests not
9+
being collected.
10+
2. Putting test_suites.py and related conftest config under root tests dir would make pytest fail to collect cfg
11+
information such as requirements, and customized session db config does not work as expected (schema not set).
12+
13+
Running sqlalchemy test suites from a separate directory does not have the aforementioned issues. Thus, we skip the
14+
path in the config, and run test suites separately.
15+
16+
To run the SQLAlchemy test suites, please specify the directory of the test suites when running pytest command:
17+
18+
```bash
19+
$cd snowflake-sqlalchemy
20+
$pytest tests/sqlalchemy_test_suite
21+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
3+
#
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
3+
#
4+
5+
from sqlalchemy.dialects import registry
6+
from sqlalchemy.testing.plugin.pytestplugin import * # noqa
7+
from sqlalchemy.testing.plugin.pytestplugin import (
8+
pytest_sessionstart as _pytest_sessionstart,
9+
)
10+
11+
import snowflake.connector
12+
from snowflake.sqlalchemy import URL
13+
14+
from ..conftest import get_db_parameters
15+
16+
registry.register("snowflake", "snowflake.sqlalchemy", "dialect")
17+
registry.register("snowflake.snowflake", "snowflake.sqlalchemy", "dialect")
18+
19+
20+
def pytest_sessionstart(session):
21+
db_parameters = get_db_parameters()
22+
session.config.option.dburi = [URL(**db_parameters)]
23+
# schema name with 'TEST_SCHEMA' is required by some tests of the sqlalchemy test suite
24+
with snowflake.connector.connect(**db_parameters) as con:
25+
con.cursor().execute("CREATE SCHEMA IF NOT EXISTS TEST_SCHEMA")
26+
_pytest_sessionstart(session)

0 commit comments

Comments
 (0)