Skip to content

Commit 5e108d1

Browse files
committed
add unit tests for the Python 3.12 autocommit transaction behaviour feature
1 parent 8b004b2 commit 5e108d1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test_autocommit.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
3+
4+
def test_executescript_rollback(fresh_db):
5+
if not hasattr(fresh_db.conn, "autocommit"):
6+
pytest.skip("No autocommit support")
7+
8+
fresh_db.conn.autocommit = False
9+
fresh_db.executescript("CREATE TABLE [test_table] ([id] INTEGER);")
10+
assert fresh_db.table_names() == ["test_table"]
11+
fresh_db.conn.rollback()
12+
assert fresh_db.table_names() == []
13+
14+
15+
def test_explicit_create_table_rollback(fresh_db):
16+
if not hasattr(fresh_db.conn, "autocommit"):
17+
pytest.skip("No autocommit support")
18+
19+
fresh_db.conn.autocommit = False
20+
fresh_db.create_table("test_table", {"id": int})
21+
assert fresh_db.table_names() == ["test_table"]
22+
fresh_db.conn.rollback()
23+
assert fresh_db.table_names() == []
24+
25+
26+
@pytest.mark.parametrize("use_table_factory", [True, False])
27+
def test_create_table_rollback(fresh_db, use_table_factory):
28+
if not hasattr(fresh_db.conn, "autocommit"):
29+
pytest.skip("No autocommit support")
30+
31+
fresh_db.conn.autocommit = False
32+
if use_table_factory:
33+
# fresh_db.create_table("test_table", {"id": int})
34+
fresh_db.table("test_table").create({"id": int})
35+
else:
36+
fresh_db["test_table"].create({"id": int})
37+
assert fresh_db.table_names() == ["test_table"]
38+
fresh_db.conn.rollback()
39+
assert fresh_db.table_names() == []

0 commit comments

Comments
 (0)