From 3c2bb6c3a80b6186946870a37c55cbdf52bcbd0d Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Fri, 21 Mar 2025 11:26:46 -0300 Subject: [PATCH 1/2] ext/python: Fix flaky tests by creating a new db for each test and removing it after the test --- bindings/python/tests/database.db | Bin 24576 -> 0 bytes bindings/python/tests/test_database.py | 36 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) delete mode 100644 bindings/python/tests/database.db diff --git a/bindings/python/tests/database.db b/bindings/python/tests/database.db deleted file mode 100644 index 89397b76e3f9c8a5c29c434a03b1e952db7be2de..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24576 zcmeI(Z)?*)90%~bq|Mf0Jz z_p?{vOAudyPlpeD30~6FrFHCqe;9-BkLK=jx!ffm^5n1Oy-e0SG_<0uX=z z1Rwwb2>iXkVbL&aH9CmJ$d}U-U*&hhsXUp<$$0hDc-pfYj?JCMleW!Q##SdHkacyZ z^?qAlGb(rO-Najh_=Z^i#;r(vwsBiP`fy2A~c6)iK420*;$6Y=k3jJ)J%dd|kDPrjk zRRY{p8cwTou@rCG&l>%g_u6MKQI?o7hBJC^n9ajgdh!)#P2@g}Z3%@D;b4%72t zCNg}KHHvL&n5IeJU09}9wBH?hbq<$DtMerq%hC+8szqJQcwkU+#{>Ao*v&J!%m1p-Ix6{ Date: Fri, 21 Mar 2025 11:52:58 -0300 Subject: [PATCH 2/2] ext/python: Close connection after each test --- bindings/python/tests/test_database.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bindings/python/tests/test_database.py b/bindings/python/tests/test_database.py index 0f0e76e68..a8276b21c 100644 --- a/bindings/python/tests/test_database.py +++ b/bindings/python/tests/test_database.py @@ -42,6 +42,8 @@ def test_fetchall_select_all_users(provider, setup_database): cursor.execute("SELECT * FROM users") users = cursor.fetchall() + + conn.close() assert users assert users == [(1, "alice"), (2, "bob")] @@ -53,6 +55,8 @@ def test_fetchall_select_user_ids(provider): cursor.execute("SELECT id FROM users") user_ids = cursor.fetchall() + + conn.close() assert user_ids assert user_ids == [(1,), (2,)] @@ -67,6 +71,8 @@ def test_in_memory_fetchone_select_all_users(provider): cursor.execute("SELECT * FROM users") alice = cursor.fetchone() + + conn.close() assert alice assert alice == (1, "alice") @@ -82,6 +88,8 @@ def test_fetchone_select_all_users(provider): assert alice == (1, "alice") bob = cursor.fetchone() + + conn.close() assert bob assert bob == (2, "bob") @@ -93,6 +101,8 @@ def test_fetchone_select_max_user_id(provider): cursor.execute("SELECT MAX(id) FROM users") max_id = cursor.fetchone() + + conn.close() assert max_id assert max_id == (2,) @@ -100,8 +110,8 @@ def test_fetchone_select_max_user_id(provider): # Test case for: https://github.com/tursodatabase/limbo/issues/494 @pytest.mark.parametrize("provider", ["sqlite3", "limbo"]) def test_commit(provider): - con = connect(provider, "tests/database.db") - cur = con.cursor() + conn = connect(provider, "tests/database.db") + cur = conn.cursor() cur.execute(""" CREATE TABLE IF NOT EXISTS users_b ( @@ -113,7 +123,7 @@ def test_commit(provider): ) """) - con.commit() + conn.commit() sample_users = [ ("alice", "alice@example.com", "admin"), @@ -125,11 +135,13 @@ def test_commit(provider): for username, email, role in sample_users: cur.execute("INSERT INTO users_b (username, email, role) VALUES (?, ?, ?)", (username, email, role)) - con.commit() + conn.commit() # Now query the table res = cur.execute("SELECT * FROM users_b") record = res.fetchone() + + conn.close() assert record