Skip to content

Commit 9b5680a

Browse files
fix: close leaked catalogs in test_datafusion.py and test_upsert.py fixtures
Fixes ResourceWarning unclosed database connections in catalog fixtures. Both files had local catalog fixtures that returned InMemoryCatalog/Catalog instances without yielding or calling close(), leaving SQLite connections uncovered. Changed fixtures to generators that yield and close the catalog on teardown, matching the pattern established in conftest.py and elsewhere on this branch for issue apache#2530. Co-Authored-By: Claude Haiku 4.5 <[email protected]>
1 parent 20d352c commit 9b5680a

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎tests/table/test_datafusion.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818

19+
from collections.abc import Iterator
1920
from pathlib import Path
2021

2122
import pyarrow as pa
@@ -31,13 +32,14 @@ def warehouse(tmp_path_factory: pytest.TempPathFactory) -> Path:
3132

3233

3334
@pytest.fixture(scope="session")
34-
def catalog(warehouse: Path) -> Catalog:
35-
catalog = load_catalog(
35+
def catalog(warehouse: Path) -> Iterator[Catalog]:
36+
cat = load_catalog(
3637
"default",
3738
uri=f"sqlite:///{warehouse}/pyiceberg_catalog.db",
3839
warehouse=f"file://{warehouse}",
3940
)
40-
return catalog
41+
yield cat
42+
cat.close()
4143

4244

4345
def test_datafusion_register_pyiceberg_table(catalog: Catalog, arrow_table_with_null: pa.Table) -> None:

‎tests/table/test_upsert.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
from collections.abc import Iterator
1718
from pathlib import PosixPath
1819

1920
import pyarrow as pa
@@ -35,10 +36,11 @@
3536

3637

3738
@pytest.fixture
38-
def catalog(tmp_path: PosixPath) -> InMemoryCatalog:
39-
catalog = InMemoryCatalog("test.in_memory.catalog", warehouse=tmp_path.absolute().as_posix())
40-
catalog.create_namespace("default")
41-
return catalog
39+
def catalog(tmp_path: PosixPath) -> Iterator[InMemoryCatalog]:
40+
cat = InMemoryCatalog("test.in_memory.catalog", warehouse=tmp_path.absolute().as_posix())
41+
cat.create_namespace("default")
42+
yield cat
43+
cat.close()
4244

4345

4446
def _drop_table(catalog: Catalog, identifier: str) -> None:

0 commit comments

Comments
 (0)