Skip to content

Commit d773c6e

Browse files
pythongh-93795: Use test.support TESTFN/unlink in sqlite3 tests (python#93796)
1 parent cdf7097 commit d773c6e

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

Lib/test/test_sqlite3/test_transactions.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,33 @@
2323
import os, unittest
2424
import sqlite3 as sqlite
2525

26+
from test.support import LOOPBACK_TIMEOUT
27+
from test.support.os_helper import TESTFN, unlink
28+
2629
from test.test_sqlite3.test_dbapi import memory_database
2730

28-
def get_db_path():
29-
return "sqlite_testdb"
31+
32+
TIMEOUT = LOOPBACK_TIMEOUT / 10
33+
3034

3135
class TransactionTests(unittest.TestCase):
3236
def setUp(self):
33-
try:
34-
os.remove(get_db_path())
35-
except OSError:
36-
pass
37-
38-
self.con1 = sqlite.connect(get_db_path(), timeout=0.1)
37+
self.con1 = sqlite.connect(TESTFN, timeout=TIMEOUT)
3938
self.cur1 = self.con1.cursor()
4039

41-
self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
40+
self.con2 = sqlite.connect(TESTFN, timeout=TIMEOUT)
4241
self.cur2 = self.con2.cursor()
4342

4443
def tearDown(self):
45-
self.cur1.close()
46-
self.con1.close()
44+
try:
45+
self.cur1.close()
46+
self.con1.close()
4747

48-
self.cur2.close()
49-
self.con2.close()
48+
self.cur2.close()
49+
self.con2.close()
5050

51-
try:
52-
os.unlink(get_db_path())
53-
except OSError:
54-
pass
51+
finally:
52+
unlink(TESTFN)
5553

5654
def test_dml_does_not_auto_commit_before(self):
5755
self.cur1.execute("create table test(i)")

0 commit comments

Comments
 (0)