Skip to content

Commit b319a15

Browse files
Add option to ensure all dialects are properly tested in CI (#526)
1 parent f93cf5a commit b319a15

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

.github/workflows/test_and_publish.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ jobs:
153153
PYTEST_MYSQL_DB_URL: mysql://gis:gis@127.0.0.1:3307/gis
154154
PYTEST_MARIADB_DB_URL: mariadb://gis:gis@127.0.0.1:3308/gis
155155
run: |
156+
export PYTEST_ADDOPTS='--require-all-dialects'
156157
if [[ ${{ matrix.python-version.flag }} == 'pypy3.8' ]]; then
157-
export PYTEST_ADDOPTS='--ignore=tests/gallery/test_insert_raster.py'
158+
export PYTEST_ADDOPTS=${PYTEST_ADDOPTS}' --ignore=tests/gallery/test_insert_raster.py'
158159
fi;
159160
# Run the unit test suite with SQLAlchemy=1.4.* and then with the latest version of SQLAlchemy
160161
tox -vv

tests/conftest.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def pytest_addoption(parser):
5757
default=False,
5858
help="If set to True, all statements of the engine are logged.",
5959
)
60+
parser.addoption(
61+
"--require-all-dialects",
62+
action="store_true",
63+
default=False,
64+
help="If set to True, all dialects muts be properly executed.",
65+
)
6066

6167

6268
def pytest_generate_tests(metafunc):
@@ -173,8 +179,14 @@ def _engine_echo(request):
173179
return _engine_echo
174180

175181

182+
@pytest.fixture(scope="session")
183+
def _require_all_dialects(request):
184+
_require_all_dialects = request.config.getoption("--require-all-dialects")
185+
return _require_all_dialects
186+
187+
176188
@pytest.fixture
177-
def engine(tmpdir, db_url, _engine_echo):
189+
def engine(tmpdir, db_url, _engine_echo, _require_all_dialects):
178190
"""Provide an engine to test database."""
179191
try:
180192
if db_url.startswith("sqlite:///"):
@@ -196,7 +208,11 @@ def engine(tmpdir, db_url, _engine_echo):
196208
current_engine = create_engine(db_url, echo=_engine_echo)
197209
current_engine.update_execution_options(search_path=["gis", "public"])
198210
except Exception:
199-
pytest.skip(reason=f"Could not create engine for this URL: {db_url}")
211+
msg = f"Could not create engine for this URL: {db_url}"
212+
if _require_all_dialects:
213+
pytest.fail("All dialects are required. " + msg)
214+
else:
215+
pytest.skip(reason=msg)
200216

201217
# Disambiguate MySQL and MariaDB
202218
if current_engine.dialect.name in ["mysql", "mariadb"]:
@@ -208,9 +224,17 @@ def engine(tmpdir, db_url, _engine_echo):
208224
else "MySQL"
209225
)
210226
if current_engine.dialect.name != mysql_type.lower():
211-
pytest.skip(reason=f"Can not execute {mysql_type} queries on {db_url}")
227+
msg = f"Can not execute {mysql_type} queries on {db_url}"
228+
if _require_all_dialects:
229+
pytest.fail("All dialects are required. " + msg)
230+
else:
231+
pytest.skip(reason=msg)
212232
except InvalidRequestError:
213-
pytest.skip(reason=f"Can not execute MariaDB queries on {db_url}")
233+
msg = f"Can not execute MariaDB queries on {db_url}"
234+
if _require_all_dialects:
235+
pytest.fail("All dialects are required. " + msg)
236+
else:
237+
pytest.skip(reason=msg)
214238

215239
yield current_engine
216240
current_engine.dispose()

0 commit comments

Comments
 (0)