2
2
# Copyright (c) 2012-2022 Snowflake Computing Inc. All rights reserved.
3
3
#
4
4
5
+ import sqlalchemy .testing .config
6
+ from sqlalchemy import util
5
7
from sqlalchemy .dialects import registry
6
8
from sqlalchemy .testing .plugin .pytestplugin import * # noqa
7
9
from sqlalchemy .testing .plugin .pytestplugin import (
15
17
from snowflake .sqlalchemy import URL
16
18
17
19
from ..conftest import get_db_parameters
20
+ from ..util import random_string
18
21
19
22
registry .register ("snowflake" , "snowflake.sqlalchemy" , "dialect" )
20
23
registry .register ("snowflake.snowflake" , "snowflake.sqlalchemy" , "dialect" )
21
- sqlalchemy_test_schema = "TEST_SCHEMA"
24
+ TEST_SCHEMA = f"test_schema_{ random_string (5 )} "
25
+ TEST_SCHEMA_2 = f"{ TEST_SCHEMA } _2"
26
+
27
+
28
+ # patch sqlalchemy.testing.config.Confi.__init__ for schema name randomization
29
+ # same schema name would result in conflict as we're running tests in parallel in the CI
30
+ def config_patched__init__ (self , db , db_opts , options , file_config ):
31
+ self ._set_name (db )
32
+ self .db = db
33
+ self .db_opts = db_opts
34
+ self .options = options
35
+ self .file_config = file_config
36
+ self .test_schema = TEST_SCHEMA
37
+ self .test_schema_2 = TEST_SCHEMA_2
38
+
39
+ self .is_async = db .dialect .is_async and not util .asbool (
40
+ db .url .query .get ("async_fallback" , False )
41
+ )
42
+
43
+
44
+ sqlalchemy .testing .config .Config .__init__ = config_patched__init__
22
45
23
46
24
47
def pytest_sessionstart (session ):
@@ -27,13 +50,13 @@ def pytest_sessionstart(session):
27
50
# schema name with 'TEST_SCHEMA' is required by some tests of the sqlalchemy test suite
28
51
with snowflake .connector .connect (** db_parameters ) as con :
29
52
con .cursor ().execute (f"CREATE SCHEMA IF NOT EXISTS { db_parameters ['schema' ]} " )
30
- con .cursor ().execute (f"CREATE SCHEMA IF NOT EXISTS { sqlalchemy_test_schema } ;" )
53
+ con .cursor ().execute (f"CREATE SCHEMA IF NOT EXISTS { TEST_SCHEMA } ;" )
31
54
_pytest_sessionstart (session )
32
55
33
56
34
57
def pytest_sessionfinish (session ):
35
58
db_parameters = get_db_parameters ()
36
59
with snowflake .connector .connect (** db_parameters ) as con :
37
60
con .cursor ().execute (f"DROP SCHEMA IF EXISTS { db_parameters ['schema' ]} " )
38
- con .cursor ().execute (f"DROP SCHEMA IF EXISTS f{ sqlalchemy_test_schema } " )
61
+ con .cursor ().execute (f"DROP SCHEMA IF EXISTS f{ TEST_SCHEMA } " )
39
62
_pytest_sessionfinish (session )
0 commit comments