Skip to content

Commit e687110

Browse files
committed
fix: Properly dispose SQLAlchemy engine in test fixtures
Added db.engine.dispose() and gc.collect() after db.drop_all() to ensure all database connections are properly closed before pytest session teardown. This fixes the ExceptionGroup teardown error.
1 parent 36689f7 commit e687110

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
import threading
44
import time
5+
import gc
6+
import atexit
57
from pathlib import Path
68

79
import pytest
@@ -57,6 +59,9 @@ def app(tmp_path_factory):
5759
yield flask_app
5860
db.session.remove()
5961
db.drop_all()
62+
# Dispose engine to close all connections and prevent teardown errors
63+
db.engine.dispose()
64+
gc.collect()
6065

6166

6267
@pytest.fixture(scope="session")
@@ -98,6 +103,9 @@ def browser_app(tmp_path_factory):
98103
yield flask_app
99104
db.session.remove()
100105
db.drop_all()
106+
# Dispose engine to close all connections and prevent teardown errors
107+
db.engine.dispose()
108+
gc.collect()
101109

102110

103111
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)