@@ -1751,20 +1751,24 @@ class ExecutionConcurrentlyCloseConnectionBaseTests:
17511751 @classmethod
17521752 def setUpClass (cls ):
17531753 super ().setUpClass ()
1754+ # A fresh module is required for this class so that adapters
1755+ # registered by the tests do not pollute other tests.
17541756 cls .sqlite = import_helper .import_fresh_module ("sqlite3" , fresh = ["_sqlite3" ])
17551757
17561758 def inittest (self , ** adapters ):
17571759 """Return a pair (connection, connection or cursor) to use in tests."""
17581760 # Counter for the number of calls to the tracked functions.
17591761 self .ncalls = Counter ()
1760- self .colname = "a"
17611762
17621763 cx = self .sqlite .connect (":memory:" )
1764+ self .addCleanup (cx .close )
1765+
17631766 # table to use to query the database to ensure that it's not closed
1764- cx .execute (f"create table canary({ self .colname } nunmber)" )
1765- cx .execute (f"insert into canary({ self .colname } ) values (?)" , (1 ,))
1767+ cx .execute (f"create table canary(flag nunmber)" )
1768+ cx .execute (f"insert into canary values (?)" , (1 ,))
1769+
1770+ self .colname = "a"
17661771 cx .execute (f"create table tmp({ self .colname } number)" )
1767- self .addCleanup (cx .close )
17681772 return cx , self .executor (cx )
17691773
17701774 def executor (self , connection ):
@@ -1779,18 +1783,20 @@ def check_alive(self, executor):
17791783 def check_execute (self , executor , payload , * , named = False ):
17801784 self .assertEqual (self .ncalls .total (), 0 )
17811785 self .check_alive (executor )
1786+
1787+ binding = f"(:{ self .colname } )" if named else "(?)"
17821788 msg = r"Cannot operate on a closed database\."
1783- binding = "(:a)" if named else "(?)"
17841789 with self .assertRaisesRegex (self .sqlite .ProgrammingError , msg ):
1785- executor .execute (f"insert into tmp(a) values { binding } " , payload )
1790+ executor .execute (f"insert into tmp values { binding } " , payload )
17861791
17871792 def check_executemany (self , executor , payload , * , named = False ):
17881793 self .assertEqual (self .ncalls .total (), 0 )
17891794 self .check_alive (executor )
1795+
1796+ binding = f"(:{ self .colname } )" if named else "(?)"
17901797 msg = r"Cannot operate on a closed database\."
1791- binding = "(:a)" if named else "(?)"
17921798 with self .assertRaisesRegex (self .sqlite .ProgrammingError , msg ):
1793- executor .executemany (f"insert into tmp(a) values { binding } " , payload )
1799+ executor .executemany (f"insert into tmp values { binding } " , payload )
17941800
17951801 # Simple tests
17961802
@@ -2002,7 +2008,6 @@ def executor(self, connection):
20022008 return connection .cursor ()
20032009
20042010
2005-
20062011class ClosedConTests (unittest .TestCase ):
20072012 def check (self , fn , * args , ** kwds ):
20082013 regex = "Cannot operate on a closed database."
0 commit comments