This is an automated email from the ASF dual-hosted git repository.

kevinjqliu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 7d4a8ef6 fix: ignore local config during tests (#3006)
7d4a8ef6 is described below

commit 7d4a8ef65d92ea52953136457d5ec277728dad9d
Author: geruh <[email protected]>
AuthorDate: Mon Feb 9 18:08:22 2026 -0800

    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
---
 tests/conftest.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tests/conftest.py b/tests/conftest.py
index 4de0a190..e042924b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -40,6 +40,7 @@ from typing import (
     TYPE_CHECKING,
     Any,
 )
+from unittest import mock
 
 import boto3
 import pytest
@@ -112,6 +113,20 @@ def pytest_collection_modifyitems(items: 
list[pytest.Item]) -> None:
             item.add_marker("unmarked")
 
 
[email protected](autouse=True, scope="session")
+def _isolate_pyiceberg_config() -> None:
+    """Make test runs ignore your local PyIceberg config.
+
+    Without this, tests will attempt to resolve a local ~/.pyiceberg.yaml 
while running pytest.
+    This replaces the global catalog config once at session start with an 
env-only config.
+    """
+    import pyiceberg.catalog as _catalog_module
+    from pyiceberg.utils.config import Config
+
+    with mock.patch.object(Config, "_from_configuration_files", 
return_value=None):
+        _catalog_module._ENV_CONFIG = Config()
+
+
 def pytest_addoption(parser: pytest.Parser) -> None:
     # S3 options
     parser.addoption(

Reply via email to