Skip to content

Commit 68bcfee

Browse files
committed
Merge pull request #245 from hoh/remove_sqlite3_cli_dependency
tests: use builtin sqlite3 library instead of 'sqlite3' CLI
2 parents b48c02d + 6d6b4bc commit 68bcfee

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pytest_django_test/db_helpers.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import subprocess
3+
import sqlite3
34

45
import pytest
56

@@ -147,9 +148,13 @@ def mark_database():
147148
if get_db_engine() == 'sqlite3':
148149
if TEST_DB_NAME == ':memory:':
149150
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()
153158
return
154159

155160
raise AssertionError('%s cannot be tested properly!' % get_db_engine())
@@ -171,9 +176,16 @@ def mark_exists():
171176
if TEST_DB_NAME == ':memory:':
172177
raise AssertionError(
173178
'sqlite in-memory database cannot be checked for mark!')
174-
r = run_cmd('sqlite3', TEST_DB_NAME, 'SELECT 1 FROM mark_table')
175179

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()
177189

178190
raise AssertionError('%s cannot be tested properly!' % get_db_engine())
179191

0 commit comments

Comments
 (0)