[Python-checkins] gh-93795: Use test.support TESTFN/unlink in sqlite3 tests (#93796)

erlend-aasland webhook-mailer at python.org
Tue Jun 14 10:03:05 EDT 2022


https://github.com/python/cpython/commit/d773c6e95a1675d0d34ddc57290d624b982b7158
commit: d773c6e95a1675d0d34ddc57290d624b982b7158
branch: main
author: Erlend Egeberg Aasland <erlend.aasland at protonmail.com>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2022-06-14T16:02:52+02:00
summary:

gh-93795: Use test.support TESTFN/unlink in sqlite3 tests (#93796)

files:
M Lib/test/test_sqlite3/test_transactions.py

diff --git a/Lib/test/test_sqlite3/test_transactions.py b/Lib/test/test_sqlite3/test_transactions.py
index 040ab1ee608cf..21acad8383c29 100644
--- a/Lib/test/test_sqlite3/test_transactions.py
+++ b/Lib/test/test_sqlite3/test_transactions.py
@@ -23,35 +23,33 @@
 import os, unittest
 import sqlite3 as sqlite
 
+from test.support import LOOPBACK_TIMEOUT
+from test.support.os_helper import TESTFN, unlink
+
 from test.test_sqlite3.test_dbapi import memory_database
 
-def get_db_path():
-    return "sqlite_testdb"
+
+TIMEOUT = LOOPBACK_TIMEOUT / 10
+
 
 class TransactionTests(unittest.TestCase):
     def setUp(self):
-        try:
-            os.remove(get_db_path())
-        except OSError:
-            pass
-
-        self.con1 = sqlite.connect(get_db_path(), timeout=0.1)
+        self.con1 = sqlite.connect(TESTFN, timeout=TIMEOUT)
         self.cur1 = self.con1.cursor()
 
-        self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
+        self.con2 = sqlite.connect(TESTFN, timeout=TIMEOUT)
         self.cur2 = self.con2.cursor()
 
     def tearDown(self):
-        self.cur1.close()
-        self.con1.close()
+        try:
+            self.cur1.close()
+            self.con1.close()
 
-        self.cur2.close()
-        self.con2.close()
+            self.cur2.close()
+            self.con2.close()
 
-        try:
-            os.unlink(get_db_path())
-        except OSError:
-            pass
+        finally:
+            unlink(TESTFN)
 
     def test_dml_does_not_auto_commit_before(self):
         self.cur1.execute("create table test(i)")



More information about the Python-checkins mailing list