Skip to content

Commit 7a69798

Browse files
author
Erlend E. Aasland
committed
Use test.support.os_helper.temp_dir() in test_error_code_on_exception()
1 parent 8d11bc5 commit 7a69798

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Lib/sqlite3/test/dbapi.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import unittest
2828

2929
from test.support import check_disallow_instantiation, threading_helper, bigmemtest
30-
from test.support.os_helper import TESTFN, unlink
30+
from test.support.os_helper import TESTFN, unlink, temp_dir
3131

3232

3333
# Helper for tests using TESTFN
@@ -172,11 +172,12 @@ def test_module_constants(self):
172172

173173
def test_error_code_on_exception(self):
174174
err_msg = "unable to open database file"
175-
with self.assertRaisesRegex(sqlite.Error, err_msg) as cm:
176-
sqlite.connect("/no/such/file/exists")
177-
e = cm.exception
178-
self.assertEqual(e.sqlite_errorcode, sqlite.SQLITE_CANTOPEN)
179-
self.assertEqual(e.sqlite_errorname, "SQLITE_CANTOPEN")
175+
with temp_dir() as db:
176+
with self.assertRaisesRegex(sqlite.Error, err_msg) as cm:
177+
sqlite.connect(db)
178+
e = cm.exception
179+
self.assertEqual(e.sqlite_errorcode, sqlite.SQLITE_CANTOPEN)
180+
self.assertEqual(e.sqlite_errorname, "SQLITE_CANTOPEN")
180181

181182
# sqlite3_enable_shared_cache() is deprecated on macOS and calling it may raise
182183
# OperationalError on some buildbots.

0 commit comments

Comments
 (0)