Skip to content

Commit aede85c

Browse files
committed
fix: skip db2 test modules when db2-sqlglot-dialect not installed (not just Python version check)
1 parent ed6ba60 commit aede85c

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎tests/core/engine_adapter/integration/test_integration_db2.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import importlib.util
12
import sys
23
import typing as t
34

45
import pytest
56

6-
# Skip entire module if Python < 3.10 BEFORE any DB2 imports
7-
# DB2 adapter requires Python 3.10+ for db2-sqlglot-dialect dependency
8-
if sys.version_info < (3, 10):
7+
# Skip entire module if Python < 3.10 or db2-sqlglot-dialect is not installed.
8+
# The dialect package must be present before db2.py is imported because
9+
# class-level exp.DataType.build(dialect="db2") runs at import time.
10+
if sys.version_info < (3, 10) or importlib.util.find_spec("db2_sqlglot") is None:
911
pytest.skip(
10-
"DB2 adapter requires Python 3.10+ for db2-sqlglot-dialect", allow_module_level=True
12+
"DB2 adapter requires Python 3.10+ and db2-sqlglot-dialect", allow_module_level=True
1113
)
1214

1315
import pandas as pd # noqa: TID253

‎tests/core/engine_adapter/test_db2.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# type: ignore
2+
import importlib.util
23
import sys
34
import typing as t
45

56
import pytest
67

7-
# Skip entire module if Python < 3.10 BEFORE any DB2 imports
8-
# DB2 adapter requires Python 3.10+ for db2-sqlglot-dialect dependency
9-
if sys.version_info < (3, 10):
8+
# Skip entire module if Python < 3.10 or db2-sqlglot-dialect is not installed.
9+
# The dialect package must be present before db2.py is imported because
10+
# class-level exp.DataType.build(dialect="db2") runs at import time.
11+
if sys.version_info < (3, 10) or importlib.util.find_spec("db2_sqlglot") is None:
1012
pytest.skip(
11-
"DB2 adapter requires Python 3.10+ for db2-sqlglot-dialect", allow_module_level=True
13+
"DB2 adapter requires Python 3.10+ and db2-sqlglot-dialect", allow_module_level=True
1214
)
1315

1416
from pytest_mock.plugin import MockerFixture

0 commit comments

Comments
 (0)