diff --git a/test/test_codebook_to_pdf.py b/test/test_codebook_to_pdf.py
index ca6bd30f45a18b5ec5fd505b010b6c0d08345684..3dafcf76494e7a409541ff0f2b8a32f552db8b95 100644
--- a/test/test_codebook_to_pdf.py
+++ b/test/test_codebook_to_pdf.py
@@ -52,4 +52,5 @@ class ExportTest(unittest.TestCase):
         # Delete generated files
         os.remove(file_path_full)
         os.remove(file_path_small)
+        database.conn.close()
         os.remove(TESTDBPATH)
diff --git a/test/test_database.py b/test/test_database.py
index c9a6598e63977ff4e3fa145ee2a00d63e4757cb9..84a5b2d270495f3660bc1cb82030f5a8897a8e6a 100644
--- a/test/test_database.py
+++ b/test/test_database.py
@@ -295,7 +295,7 @@ class DatabaseTest(unittest.TestCase):
 
     def delete_db(self):
         """Delete generated database-file."""
-        del self.database
+        self.database.conn.close()
         if os.path.exists(TESTDBPATH):
             os.remove(TESTDBPATH)