Skip to content

Commit 4bbc653

Browse files
committed
Modified e2e tests to support parallel execution
1 parent bf24771 commit 4bbc653

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

tests/e2e/test_parameterized_queries.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,8 @@ class TestParameterizedQueries(PySQLPytestTestCase):
119119
def _get_inline_table_column(self, value):
120120
return self.inline_type_map[Primitive(value)]
121121

122-
@pytest.fixture(scope="class")
123-
def inline_table(self, connection_details):
124-
self.arguments = connection_details.copy()
125-
"""This table is necessary to verify that a parameter sent with INLINE
126-
approach can actually write to its analogous data type.
127-
128-
For example, a Python Decimal(), when rendered inline, should be able
129-
to read/write into a DECIMAL column in Databricks
130-
131-
Note that this fixture doesn't clean itself up. So the table will remain
132-
in the schema for use by subsequent test runs.
133-
"""
134-
135-
# Generate unique table name to avoid conflicts in parallel execution
136-
table_name = f"pysql_e2e_inline_param_test_table_{str(uuid4()).replace('-', '_')}"
137-
self.inline_table_name = table_name
138-
122+
def _create_inline_table(self, table_name):
123+
"""Create the inline test table with all necessary columns"""
139124
query = f"""
140125
CREATE TABLE IF NOT EXISTS {table_name} (
141126
null_col INT,
@@ -160,6 +145,24 @@ def inline_table(self, connection_details):
160145
with conn.cursor() as cursor:
161146
cursor.execute(query)
162147

148+
@pytest.fixture(scope="class")
149+
def inline_table(self, connection_details):
150+
self.arguments = connection_details.copy()
151+
"""This table is necessary to verify that a parameter sent with INLINE
152+
approach can actually write to its analogous data type.
153+
154+
For example, a Python Decimal(), when rendered inline, should be able
155+
to read/write into a DECIMAL column in Databricks
156+
157+
Note that this fixture doesn't clean itself up. So the table will remain
158+
in the schema for use by subsequent test runs.
159+
"""
160+
161+
# Generate unique table name to avoid conflicts in parallel execution
162+
table_name = f"pysql_e2e_inline_param_test_table_{str(uuid4()).replace('-', '_')}"
163+
self.inline_table_name = table_name
164+
self._create_inline_table(table_name)
165+
163166
@contextmanager
164167
def patch_server_supports_native_params(self, supports_native_params: bool = True):
165168
"""Applies a patch so we can test the connector's behaviour under different SPARK_CLI_SERVICE_PROTOCOL_VERSION conditions."""
@@ -184,6 +187,11 @@ def _inline_roundtrip(self, params: dict, paramstyle: ParamStyle, target_column)
184187
:paramstyle:
185188
This is a no-op but is included to make the test-code easier to read.
186189
"""
190+
if not hasattr(self, 'inline_table_name'):
191+
table_name = f"pysql_e2e_inline_param_test_table_{str(uuid4()).replace('-', '_')}"
192+
self.inline_table_name = table_name
193+
self._create_inline_table(table_name)
194+
187195
table_name = self.inline_table_name
188196
INSERT_QUERY = f"INSERT INTO {table_name} (`{target_column}`) VALUES (%(p)s)"
189197
SELECT_QUERY = f"SELECT {target_column} `col` FROM {table_name} LIMIT 1"

tests/e2e/test_variant_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def variant_table(self, connection_details):
4040
f"""
4141
INSERT INTO {table_name}
4242
VALUES
43-
(1, PARSE_JSON('{"name": "John", "age": 30}'), 'regular string'),
43+
(1, PARSE_JSON('{{\"name\": \"John\", \"age\": 30}}'), 'regular string'),
4444
(2, PARSE_JSON('[1, 2, 3, 4]'), 'another string')
4545
"""
4646
)

0 commit comments

Comments
 (0)