Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Wire test_users cleanup into pytest teardown_module so it runs under pytest, not just main()

Murtaza Nasirf22d8862be2b
diff --git a/tests/test_api_v1_parity.py b/tests/test_api_v1_parity.py
index 25ed59c7..47edb251 100644
--- a/tests/test_api_v1_parity.py
+++ b/tests/test_api_v1_parity.py
@@ -146,6 +146,13 @@ def cleanup_test_users():
db.session.commit()
+def teardown_module(module):
+ """pytest auto-calls this after the last test in the module finishes.
+ Required because pytest does not invoke ``main()``, so the cleanup in
+ its ``finally`` block never runs under ``pytest tests/``."""
+ cleanup_test_users()
+
+
def main():
print("=== Issue #274: API v1 parity ===\n")
try:
diff --git a/tests/test_reprocess_hotwords.py b/tests/test_reprocess_hotwords.py
index b707dc06..93561f42 100644
--- a/tests/test_reprocess_hotwords.py
+++ b/tests/test_reprocess_hotwords.py
@@ -221,6 +221,13 @@ def cleanup_test_users():
db.session.commit()
+def teardown_module(module):
+ """pytest auto-calls this after the last test in the module finishes.
+ Required because pytest does not invoke ``main()``, so the cleanup in
+ its ``finally`` block never runs under ``pytest tests/``."""
+ cleanup_test_users()
+
+
def main():
print("=== Issue #265: reprocess hotwords/initial_prompt precedence ===\n")
try:
diff --git a/tests/test_transcription_model_override.py b/tests/test_transcription_model_override.py
index 0ded8dd8..bf856433 100644
--- a/tests/test_transcription_model_override.py
+++ b/tests/test_transcription_model_override.py
@@ -288,6 +288,13 @@ def cleanup_test_users():
db.session.commit()
+def teardown_module(module):
+ """pytest auto-calls this after the last test in the module finishes.
+ Required because pytest does not invoke ``main()``, so the cleanup in
+ its ``finally`` block never runs under ``pytest tests/``."""
+ cleanup_test_users()
+
+
def main():
print("=== Issue #266: per-upload/tag/folder transcription model ===\n")
try: