Add db.engine.dispose() in test tearDown to fix ResourceWarning from Python 3.13.

This commit is contained in:
2026-01-11 10:54:13 +08:00
parent 3adcaa61d3
commit 693c5890ca
11 changed files with 150 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/1
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -105,6 +105,15 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"],
f"{PREFIX}/{BANK.code}")
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/1/26
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import unittest
import httpx
from flask import Flask
from test_site import db
from testlib import create_test_app, get_client
LIST_URI: str = "/accounting/base-accounts"
@@ -42,6 +43,15 @@ class BaseAccountTestCase(unittest.TestCase):
self.__app: Flask = create_test_app()
"""The Flask application."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/4/10
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -45,6 +45,15 @@ class ConsoleCommandTestCase(unittest.TestCase):
self.__app: Flask = create_test_app()
"""The Flask application."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_init_db(self) -> None:
"""Tests the "accounting-init-db" console command.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/1
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -94,6 +94,15 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], f"{PREFIX}/{EUR.code}")
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/28
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import httpx
from flask import Flask
from accounting.utils.next_uri import encode_next
from test_site import db
from testlib import NEXT_URI, Accounts, create_test_app, get_client, \
get_csrf_token, add_journal_entry
@@ -52,6 +53,15 @@ class DescriptionEditorTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_description_editor(self) -> None:
"""Test the description editor.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/24
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -63,6 +63,15 @@ class CashReceiptJournalEntryTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.
@@ -688,6 +697,15 @@ class CashDisbursementJournalEntryTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.
@@ -1289,6 +1307,15 @@ class TransferJournalEntryTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.
@@ -2169,6 +2196,15 @@ class JournalEntryReorderTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_change_date(self) -> None:
"""Tests to change the date of a journal entry.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/11
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -63,6 +63,15 @@ class OffsetTestCase(unittest.TestCase):
"""The offset test data."""
self.__data.populate()
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_add_receivable_offset(self) -> None:
"""Tests to add the receivable offset.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/22
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -55,6 +55,15 @@ class OptionTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/4/9
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import unittest
import httpx
from flask import Flask
from test_site import db
from test_site.lib import BaseTestData
from testlib import create_test_app, get_client, get_csrf_token, Accounts
@@ -54,6 +55,15 @@ class ReportTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/4/8
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -57,6 +57,15 @@ class UnmatchedOffsetTestCase(unittest.TestCase):
self.__csrf_token: str = get_csrf_token(self.__client)
"""The CSRF token."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_nobody(self) -> None:
"""Test the permission as nobody.

View File

@@ -1,7 +1,7 @@
# The Mia! Accounting Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/3
# Copyright (c) 2023 imacat.
# Copyright (c) 2023-2026 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ from accounting.utils.next_uri import append_next, inherit_next, or_next, \
encode_next, decode_next
from accounting.utils.pagination import Pagination, DEFAULT_PAGE_SIZE
from accounting.utils.query import parse_query_keywords
from test_site import db
from testlib import TEST_SERVER, create_test_app, get_csrf_token, NEXT_URI
@@ -43,6 +44,15 @@ class NextUriTestCase(unittest.TestCase):
self.__app: Flask = create_test_app()
"""The Flask application."""
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def test_next_uri(self) -> None:
"""Tests the next URI utilities with the next URI.
@@ -236,6 +246,15 @@ class PaginationTestCase(unittest.TestCase):
"""The user client."""
self.__client.headers["Referer"] = TEST_SERVER
def tearDown(self) -> None:
"""Tears down the test.
This is run once per test.
:return: None.
"""
with self.__app.app_context():
db.engine.dispose()
def __test_success(self, query: str, items: range,
result: range, is_paged: bool = True,
is_reversed: bool | None = None) -> None: