From fee1d660f9ba34d248bd5fee829f2382e9b6a82a Mon Sep 17 00:00:00 2001 From: dmitry <dima74ermilov@gmail.com> Date: Mon, 17 Mar 2025 19:43:49 +0300 Subject: [PATCH 1/2] fixup: closing connection when load sql files --- pytest_postgresql/loader.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pytest_postgresql/loader.py b/pytest_postgresql/loader.py index 1b938313..f012eb45 100644 --- a/pytest_postgresql/loader.py +++ b/pytest_postgresql/loader.py @@ -25,8 +25,8 @@ def build_loader(load: Union[Callable, str, Path]) -> Callable: def sql(sql_filename: Path, **kwargs: Any) -> None: """Database loader for sql files.""" - db_connection = psycopg.connect(**kwargs) - with open(sql_filename, "r") as _fd: - with db_connection.cursor() as cur: - cur.execute(_fd.read()) - db_connection.commit() + with psycopg.connect(**kwargs) as db_connection: + with open(sql_filename, "r") as _fd: + with db_connection.cursor() as cur: + cur.execute(_fd.read()) + db_connection.commit() From 9bb3f1b0d611a859f46ecd4e73e56a1a9d191d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=9Aliwi=C5=84ski?= <fizyk@fizyk.dev> Date: Wed, 19 Mar 2025 15:47:16 +0100 Subject: [PATCH 2/2] Add bugfix newsfragment --- newsfragments/+8bf3ab6b.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 newsfragments/+8bf3ab6b.bugfix.rst diff --git a/newsfragments/+8bf3ab6b.bugfix.rst b/newsfragments/+8bf3ab6b.bugfix.rst new file mode 100644 index 00000000..75053e51 --- /dev/null +++ b/newsfragments/+8bf3ab6b.bugfix.rst @@ -0,0 +1,3 @@ +Close postgresql connection after loading sql files. + +Fixes possible `ResourceWarning`