File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
2
import subprocess
3
+ import sqlite3
3
4
4
5
import pytest
5
6
@@ -147,9 +148,13 @@ def mark_database():
147
148
if get_db_engine () == 'sqlite3' :
148
149
if TEST_DB_NAME == ':memory:' :
149
150
raise AssertionError ('sqlite in-memory database cannot be marked!' )
150
- r = run_cmd ('sqlite3' , TEST_DB_NAME ,
151
- 'CREATE TABLE mark_table(kaka int);' )
152
- assert r .status_code == 0
151
+
152
+ conn = sqlite3 .connect (TEST_DB_NAME )
153
+ try :
154
+ with conn :
155
+ conn .execute ('CREATE TABLE mark_table(kaka int);' )
156
+ finally : # Close the DB even if an error is raised
157
+ conn .close ()
153
158
return
154
159
155
160
raise AssertionError ('%s cannot be tested properly!' % get_db_engine ())
@@ -171,9 +176,16 @@ def mark_exists():
171
176
if TEST_DB_NAME == ':memory:' :
172
177
raise AssertionError (
173
178
'sqlite in-memory database cannot be checked for mark!' )
174
- r = run_cmd ('sqlite3' , TEST_DB_NAME , 'SELECT 1 FROM mark_table' )
175
179
176
- return r .status_code == 0
180
+ conn = sqlite3 .connect (TEST_DB_NAME )
181
+ try :
182
+ with conn :
183
+ conn .execute ('SELECT 1 FROM mark_table' )
184
+ return True
185
+ except sqlite3 .OperationalError :
186
+ return False
187
+ finally : # Close the DB even if an error is raised
188
+ conn .close ()
177
189
178
190
raise AssertionError ('%s cannot be tested properly!' % get_db_engine ())
179
191
You can’t perform that action at this time.
0 commit comments