From eb89917c5a86ae4f51f08a0f0f1fcf72d95d3d44 Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Tue, 8 Sep 2026 17:19:45 -0300 Subject: [PATCH] QTZPOC-20 QTZPOC-20: Clarify broad exception handling in OPC repository and refactor asyncio imports in worker tests. --- laborious/utils/repository/opc_repository.py | 2 +- tests/laborious/worker/test_worker_main.py | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/laborious/utils/repository/opc_repository.py b/laborious/utils/repository/opc_repository.py index 802c318..9e866b3 100644 --- a/laborious/utils/repository/opc_repository.py +++ b/laborious/utils/repository/opc_repository.py @@ -79,7 +79,7 @@ def _opc_authentication_token_str(client: Client | None) -> str: if tok is None: return 'unknown' return str(tok) - except Exception: + except Exception: # NOSONAR - best-effort label for logs/metrics, must not fail loud return 'unknown' diff --git a/tests/laborious/worker/test_worker_main.py b/tests/laborious/worker/test_worker_main.py index e87aac7..44ce6d4 100644 --- a/tests/laborious/worker/test_worker_main.py +++ b/tests/laborious/worker/test_worker_main.py @@ -5,6 +5,7 @@ Everything I/O-bound (Temporal client, Prometheus HTTP server, Mongo/Postgres/Mi mocked; only the control flow inside ``worker.py`` is under test. """ +import asyncio from unittest.mock import ANY, AsyncMock, MagicMock, patch from pytest import mark, raises @@ -20,8 +21,6 @@ def test_main_exits_when_runtime_is_unset(mock_get_logger, mock_app_up, monkeypa mock_get_logger.return_value = logger with raises(SystemExit) as exc: - import asyncio - asyncio.run(main()) assert exc.value.code == 1 @@ -55,8 +54,6 @@ class TestMainHappyPath: mock_prepare_worker.return_value = worker mock_connect.return_value = MagicMock() - import asyncio - with raises(SystemExit) as exc: asyncio.run(main()) return exc.value.code @@ -198,8 +195,6 @@ class TestMainHappyPath: worker.run = AsyncMock(side_effect=RuntimeError('boom')) mock_prepare_worker.return_value = worker - import asyncio - with raises(SystemExit) as exc: asyncio.run(main())