Skip to content

Commit ce6cca5

Browse files
Prevent ResourceWarnings after test runs
eg ResourceWarning: unclosed database in <sqlite3.Connection object at 0x10ce1f010>
1 parent ba6c9b1 commit ce6cca5

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

flask_admin/tests/geoa/conftest.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55

66

77
@pytest.fixture
8-
def db():
8+
def db(app):
99
db = SQLAlchemy()
10+
1011
yield db
1112

13+
with app.app_context():
14+
db.session.close()
15+
db.engine.dispose()
16+
1217

1318
@pytest.fixture
1419
def admin(app, babel, db):

flask_admin/tests/peeweemodel/conftest.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66

77
@pytest.fixture
8-
def db():
8+
def db(app):
99
db = peewee.SqliteDatabase(":memory:")
10+
1011
yield db
1112

13+
with app.app_context():
14+
db.close()
15+
1216

1317
@pytest.fixture
1418
def admin(app, babel, db):

flask_admin/tests/sqla/conftest.py

+10
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ def db(app):
2323
app.config["SQLALCHEMY_ECHO"] = True
2424
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
2525
db = SQLAlchemy(app)
26+
2627
yield db
2728

29+
with app.app_context():
30+
db.session.close()
31+
db.engine.dispose()
32+
2833

2934
@pytest.fixture
3035
def postgres_db(app):
@@ -35,8 +40,13 @@ def postgres_db(app):
3540
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
3641

3742
db = SQLAlchemy(app)
43+
3844
yield db
3945

46+
with app.app_context():
47+
db.session.close()
48+
db.engine.dispose()
49+
4050

4151
@pytest.fixture
4252
def admin(app, babel, db):

0 commit comments

Comments
 (0)