Skip to content

Commit 78c895d

Browse files
committed
fix(tests): skip background sweeps when create_app(testing=True)
Temp cleanup and disk monitor background threads were spawning per test due to function-scoped app fixture. Add a testing parameter to create_app() that skips these sweeps; conftest.py passes it.
1 parent 6c8793b commit 78c895d

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

opencut/server.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def _init_sentry_if_configured() -> bool:
301301
# ---------------------------------------------------------------------------
302302
# Flask App Factory
303303
# ---------------------------------------------------------------------------
304-
def create_app(config=None):
304+
def create_app(config=None, testing=False):
305305
"""Create and configure the Flask application.
306306
307307
Args:
@@ -331,20 +331,19 @@ def create_app(config=None):
331331

332332
# Startup + periodic sweep of stale opencut_* temp files. Best-effort;
333333
# failure never blocks app startup.
334-
try:
335-
from opencut.core import temp_cleanup as _temp_cleanup
336-
_temp_cleanup.run_startup_sweep()
337-
_temp_cleanup.start_background_sweep()
338-
except Exception as _cleanup_exc: # noqa: BLE001
339-
logger.warning("temp_cleanup bootstrap failed: %s", _cleanup_exc)
340-
341-
# Optional disk-space background monitor (off by default, opt-in
342-
# via OPENCUT_DISK_MONITOR_INTERVAL).
343-
try:
344-
from opencut.core import disk_monitor as _disk_monitor
345-
_disk_monitor.start_background()
346-
except Exception as _disk_exc: # noqa: BLE001
347-
logger.warning("disk_monitor bootstrap failed: %s", _disk_exc)
334+
if not testing:
335+
try:
336+
from opencut.core import temp_cleanup as _temp_cleanup
337+
_temp_cleanup.run_startup_sweep()
338+
_temp_cleanup.start_background_sweep()
339+
except Exception as _cleanup_exc: # noqa: BLE001
340+
logger.warning("temp_cleanup bootstrap failed: %s", _cleanup_exc)
341+
342+
try:
343+
from opencut.core import disk_monitor as _disk_monitor
344+
_disk_monitor.start_background()
345+
except Exception as _disk_exc: # noqa: BLE001
346+
logger.warning("disk_monitor bootstrap failed: %s", _disk_exc)
348347

349348
from opencut.errors import error_response as _error_response # noqa: E402
350349
from opencut.errors import register_error_handlers

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def app():
1515
from opencut.config import OpenCutConfig
1616
from opencut.server import create_app
1717
test_config = OpenCutConfig()
18-
flask_app = create_app(config=test_config)
18+
flask_app = create_app(config=test_config, testing=True)
1919
flask_app.config["TESTING"] = True
2020
return flask_app
2121

0 commit comments

Comments
 (0)