Skip to content

Commit

Permalink
Add option to ensure all dialects are properly tested in CI (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet authored Nov 5, 2024
1 parent f93cf5a commit b319a15
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ jobs:
PYTEST_MYSQL_DB_URL: mysql://gis:[email protected]:3307/gis
PYTEST_MARIADB_DB_URL: mariadb://gis:[email protected]:3308/gis
run: |
export PYTEST_ADDOPTS='--require-all-dialects'
if [[ ${{ matrix.python-version.flag }} == 'pypy3.8' ]]; then
export PYTEST_ADDOPTS='--ignore=tests/gallery/test_insert_raster.py'
export PYTEST_ADDOPTS=${PYTEST_ADDOPTS}' --ignore=tests/gallery/test_insert_raster.py'
fi;
# Run the unit test suite with SQLAlchemy=1.4.* and then with the latest version of SQLAlchemy
tox -vv
Expand Down
32 changes: 28 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def pytest_addoption(parser):
default=False,
help="If set to True, all statements of the engine are logged.",
)
parser.addoption(
"--require-all-dialects",
action="store_true",
default=False,
help="If set to True, all dialects muts be properly executed.",
)


def pytest_generate_tests(metafunc):
Expand Down Expand Up @@ -173,8 +179,14 @@ def _engine_echo(request):
return _engine_echo


@pytest.fixture(scope="session")
def _require_all_dialects(request):
_require_all_dialects = request.config.getoption("--require-all-dialects")
return _require_all_dialects


@pytest.fixture
def engine(tmpdir, db_url, _engine_echo):
def engine(tmpdir, db_url, _engine_echo, _require_all_dialects):
"""Provide an engine to test database."""
try:
if db_url.startswith("sqlite:///"):
Expand All @@ -196,7 +208,11 @@ def engine(tmpdir, db_url, _engine_echo):
current_engine = create_engine(db_url, echo=_engine_echo)
current_engine.update_execution_options(search_path=["gis", "public"])
except Exception:
pytest.skip(reason=f"Could not create engine for this URL: {db_url}")
msg = f"Could not create engine for this URL: {db_url}"
if _require_all_dialects:
pytest.fail("All dialects are required. " + msg)
else:
pytest.skip(reason=msg)

# Disambiguate MySQL and MariaDB
if current_engine.dialect.name in ["mysql", "mariadb"]:
Expand All @@ -208,9 +224,17 @@ def engine(tmpdir, db_url, _engine_echo):
else "MySQL"
)
if current_engine.dialect.name != mysql_type.lower():
pytest.skip(reason=f"Can not execute {mysql_type} queries on {db_url}")
msg = f"Can not execute {mysql_type} queries on {db_url}"
if _require_all_dialects:
pytest.fail("All dialects are required. " + msg)
else:
pytest.skip(reason=msg)
except InvalidRequestError:
pytest.skip(reason=f"Can not execute MariaDB queries on {db_url}")
msg = f"Can not execute MariaDB queries on {db_url}"
if _require_all_dialects:
pytest.fail("All dialects are required. " + msg)
else:
pytest.skip(reason=msg)

yield current_engine
current_engine.dispose()
Expand Down

0 comments on commit b319a15

Please sign in to comment.