Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-105539: Fix ResourceWarning from unclosed SQLite connection in ClosedCurTests. #108360

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Lib/test/audit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,18 @@ def hook(event, *args):
cx2 = sqlite3.Connection(":memory:")

# Configured without --enable-loadable-sqlite-extensions
if hasattr(sqlite3.Connection, "enable_load_extension"):
cx1.enable_load_extension(False)
try:
cx1.load_extension("test")
except sqlite3.OperationalError:
pass
else:
raise RuntimeError("Expected sqlite3.load_extension to fail")

try:
if hasattr(sqlite3.Connection, "enable_load_extension"):
cx1.enable_load_extension(False)
try:
cx1.load_extension("test")
except sqlite3.OperationalError:
pass
else:
raise RuntimeError("Expected sqlite3.load_extension to fail")
finally:
cx1.close()
cx2.close()

def test_sys_getframe():
import sys
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_sqlite3/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def progress(status, remaining, total):
raise SystemError('nearly out of space')

with self.assertRaises(SystemError) as err:
with sqlite.connect(':memory:') as bck:
with memory_database() as bck:
self.cx.backup(bck, progress=progress)
self.assertEqual(str(err.exception), 'nearly out of space')

Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_sqlite3/test_dbapi.py
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from test.support.os_helper import TESTFN, TESTFN_UNDECODABLE, unlink, temp_dir, FakePath

from .util import memory_database, cx_limit
from .util import MemoryDatabaseMixin


class ModuleTests(unittest.TestCase):
Expand Down Expand Up @@ -1740,10 +1741,9 @@ def test_closed_call(self):
self.check(self.con)


class ClosedCurTests(unittest.TestCase):
class ClosedCurTests(MemoryDatabaseMixin, unittest.TestCase):
def test_closed(self):
con = sqlite.connect(":memory:")
cur = con.cursor()
cur = self.cx.cursor()
cur.close()

for method_name in ("execute", "executemany", "executescript", "fetchall", "fetchmany", "fetchone"):
Expand Down
Loading