55from contextlib import closing
66from functools import partial
77from pathlib import Path
8- from test .support import import_helper , os_helper
8+ from test .support import import_helper , os_helper , gc_collect
99
1010dbm_sqlite3 = import_helper .import_module ("dbm.sqlite3" )
1111# N.B. The test will fail on some platforms without sqlite3
@@ -32,7 +32,6 @@ def tearDown(self):
3232 for suffix in "" , "-wal" , "-shm" :
3333 os_helper .unlink (self .filename + suffix )
3434
35-
3635class URI (unittest .TestCase ):
3736
3837 def test_uri_substitutions (self ):
@@ -72,6 +71,7 @@ def setUp(self):
7271 with dbm_sqlite3 .open (self .filename , "w" ) as db :
7372 db [b"key1" ] = "value1"
7473 db [b"key2" ] = "value2"
74+ gc_collect ()
7575 self .db = dbm_sqlite3 .open (self .filename , "r" )
7676
7777 def tearDown (self ):
@@ -112,6 +112,7 @@ def setUp(self):
112112
113113 def test_readonly_file_read (self ):
114114 os .chmod (self .db_path , stat .S_IREAD )
115+ gc_collect ()
115116 with dbm_sqlite3 .open (self .db_path , "r" ) as db :
116117 self .assertEqual (db [b"key" ], b"value" )
117118
@@ -123,6 +124,7 @@ def test_readonly_file_write(self):
123124
124125 def test_readonly_dir_read (self ):
125126 os .chmod (self .test_dir , stat .S_IREAD | stat .S_IEXEC )
127+ gc_collect ()
126128 with dbm_sqlite3 .open (self .db_path , "r" ) as db :
127129 self .assertEqual (db [b"key" ], b"value" )
128130
@@ -134,6 +136,7 @@ def test_readonly_dir_write(self):
134136 modified = True # on Windows and macOS
135137 except dbm_sqlite3 .error :
136138 modified = False
139+ gc_collect ()
137140 with dbm_sqlite3 .open (self .db_path , "r" ) as db :
138141 if modified :
139142 self .assertEqual (db [b"newkey" ], b"newvalue" )
@@ -350,6 +353,7 @@ def test_corrupt_readwrite(self):
350353 check (fn = self .len_ )
351354
352355 def test_corrupt_force_new (self ):
356+ gc_collect ()
353357 with closing (dbm_sqlite3 .open (self .filename , "n" )) as db :
354358 db ["foo" ] = "write"
355359 _ = db [b"foo" ]
0 commit comments