Skip to content

Commit 7d4a8ef

Browse files
authored
fix: ignore local config during tests (#3006)
# Rationale for this change Fixes a test failure that hits anyone with PyIceberg already configured. The test uses `load_catalog("default", type="in-memory")`, which merges your dev environment config with the test parameters. If you have a `default` catalog defined in `~/.pyiceberg.yaml` with something like uri: https://best-rest-catalog.com, the merge produces `{"uri": "https://best-rest-catalog.com", "type": "in-memory"}`. SQLAlchemy sees that https:// URI and tries to load it as a database dialect, which fails wuth: ``` sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:https ``` Therefore, this PR avoids using the local pyicberg.yaml file entirely! ## Are these changes tested? Yes. I created a conflicting ~/.pyiceberg.yaml with a default catalog pointing to an HTTPS REST endpoint, confirmed the old code fails, and verified the fix bypasses the config merge and works. ## Are there any user-facing changes? No
1 parent b98de51 commit 7d4a8ef

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
TYPE_CHECKING,
4141
Any,
4242
)
43+
from unittest import mock
4344

4445
import boto3
4546
import pytest
@@ -112,6 +113,20 @@ def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
112113
item.add_marker("unmarked")
113114

114115

116+
@pytest.fixture(autouse=True, scope="session")
117+
def _isolate_pyiceberg_config() -> None:
118+
"""Make test runs ignore your local PyIceberg config.
119+
120+
Without this, tests will attempt to resolve a local ~/.pyiceberg.yaml while running pytest.
121+
This replaces the global catalog config once at session start with an env-only config.
122+
"""
123+
import pyiceberg.catalog as _catalog_module
124+
from pyiceberg.utils.config import Config
125+
126+
with mock.patch.object(Config, "_from_configuration_files", return_value=None):
127+
_catalog_module._ENV_CONFIG = Config()
128+
129+
115130
def pytest_addoption(parser: pytest.Parser) -> None:
116131
# S3 options
117132
parser.addoption(

0 commit comments

Comments
 (0)