Skip to content

Commit 01f3b56

Browse files
test: add regression test for Python 3.13 ResourceWarning fix (apache#2530)
Adds test_catalog_fixture_closes_connections to TestSqlCatalogClose to verify that SqlCatalog properly disposes all SQLAlchemy connections during teardown. Prevents future regressions where catalog.close() is accidentally removed from fixture teardown.
1 parent 83f789d commit 01f3b56

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎tests/catalog/test_sql.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,22 @@ def test_sql_catalog_multiple_close_calls(self, catalog_sqlite: SqlCatalog) -> N
281281
catalog_sqlite.close()
282282

283283
# Second close should not raise an exception
284-
catalog_sqlite.close()
284+
catalog_sqlite.close( )
285+
def test_catalog_fixture_closes_connections(self, warehouse: Path) -> None:
286+
"""Regression test: verify SqlCatalog properly closes all SQLAlchemy
287+
connections to prevent Python 3.13 ResourceWarning about unclosed
288+
database connections. See: apache/iceberg-python#2530"""
289+
import gc
290+
import warnings
291+
292+
props = {
293+
"uri": f"sqlite:////{warehouse}/test-regression-2530",
294+
"warehouse": f"file://{warehouse}",
295+
}
296+
with warnings.catch_warnings():
297+
warnings.simplefilter("error", ResourceWarning)
298+
catalog = SqlCatalog("regression_test", **props)
299+
catalog.create_tables()
300+
catalog.destroy_tables()
301+
catalog.close()
302+
gc.collect() # Force GC to catch any unclosed connections

0 commit comments

Comments
 (0)