Skip to content

Commit

Permalink
tests: explicitly close sqlite3 connections
Browse files Browse the repository at this point in the history
on Python 3.11, the Windows CI started crashing due to the database file
remainig open unexpectly in test shutdown; this attemps to fix that
  • Loading branch information
wisp3rwind committed May 4, 2023
1 parent edfbb44 commit 2e8da06
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/test_dbcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def setUpClass(cls):
'insert into test (field_one, field_two) values (4, 2)'
)
old_lib._connection().commit()
old_lib._connection().close()
del old_lib

@classmethod
Expand All @@ -190,33 +191,39 @@ def test_open_with_same_fields_leaves_untouched(self):
c = new_lib._connection().cursor()
c.execute("select * from test")
row = c.fetchone()
c.connection.close()
self.assertEqual(len(row.keys()), len(ModelFixture2._fields))

def test_open_with_new_field_adds_column(self):
new_lib = DatabaseFixture3(self.libfile)
c = new_lib._connection().cursor()
c.execute("select * from test")
row = c.fetchone()
c.connection.close()
self.assertEqual(len(row.keys()), len(ModelFixture3._fields))

def test_open_with_fewer_fields_leaves_untouched(self):
new_lib = DatabaseFixture1(self.libfile)
c = new_lib._connection().cursor()
c.execute("select * from test")
row = c.fetchone()
c.connection.close()
self.assertEqual(len(row.keys()), len(ModelFixture2._fields))

def test_open_with_multiple_new_fields(self):
new_lib = DatabaseFixture4(self.libfile)
c = new_lib._connection().cursor()
c.execute("select * from test")
row = c.fetchone()
c.connection.close()
self.assertEqual(len(row.keys()), len(ModelFixture4._fields))

def test_extra_model_adds_table(self):
new_lib = DatabaseFixtureTwoModels(self.libfile)
try:
new_lib._connection().execute("select * from another")
c = new_lib._connection()
c.execute("select * from another")
c.close()
except sqlite3.OperationalError:
self.fail("select failed")

Expand Down

0 comments on commit 2e8da06

Please sign in to comment.