Skip to content

Commit 3f0e816

Browse files
quintusdiasjorisvandenbossche
authored andcommitted
TST: Fix sqlite3 transactions test (pandas-dev#28450)
The sqlite connection is already in transaction when the test starts, so when the test intentionally raises an exception, the entire transaction, including the table creation, gets rolled back, so there is no table to query. Wrapping the table CREATE statement in its own transaction avoids the issue.
1 parent 08184ff commit 3f0e816

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

pandas/tests/io/test_sql.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import numpy as np
2727
import pytest
2828

29-
from pandas.compat import PY36
30-
3129
from pandas.core.dtypes.common import is_datetime64_dtype, is_datetime64tz_dtype
3230

3331
import pandas as pd
@@ -538,11 +536,11 @@ def _to_sql_save_index(self):
538536
assert ix_cols == [["A"]]
539537

540538
def _transaction_test(self):
541-
self.pandasSQL.execute("CREATE TABLE test_trans (A INT, B TEXT)")
542-
543-
ins_sql = "INSERT INTO test_trans (A,B) VALUES (1, 'blah')"
539+
with self.pandasSQL.run_transaction() as trans:
540+
trans.execute("CREATE TABLE test_trans (A INT, B TEXT)")
544541

545542
# Make sure when transaction is rolled back, no rows get inserted
543+
ins_sql = "INSERT INTO test_trans (A,B) VALUES (1, 'blah')"
546544
try:
547545
with self.pandasSQL.run_transaction() as trans:
548546
trans.execute(ins_sql)
@@ -2213,8 +2211,6 @@ def test_to_sql_save_index(self):
22132211
self._to_sql_save_index()
22142212

22152213
def test_transactions(self):
2216-
if PY36:
2217-
pytest.skip("not working on python > 3.5")
22182214
self._transaction_test()
22192215

22202216
def _get_sqlite_column_type(self, table, column):

0 commit comments

Comments
 (0)