QTZPOC-20
QTZPOC-20: Clarify broad exception handling in OPC repository and refactor asyncio imports in worker tests.
This commit is contained in:
@@ -79,7 +79,7 @@ def _opc_authentication_token_str(client: Client | None) -> str:
|
|||||||
if tok is None:
|
if tok is None:
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
return str(tok)
|
return str(tok)
|
||||||
except Exception:
|
except Exception: # NOSONAR - best-effort label for logs/metrics, must not fail loud
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
mocked; only the control flow inside ``worker.py`` is under test.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from unittest.mock import ANY, AsyncMock, MagicMock, patch
|
from unittest.mock import ANY, AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from pytest import mark, raises
|
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
|
mock_get_logger.return_value = logger
|
||||||
|
|
||||||
with raises(SystemExit) as exc:
|
with raises(SystemExit) as exc:
|
||||||
import asyncio
|
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
assert exc.value.code == 1
|
assert exc.value.code == 1
|
||||||
@@ -55,8 +54,6 @@ class TestMainHappyPath:
|
|||||||
mock_prepare_worker.return_value = worker
|
mock_prepare_worker.return_value = worker
|
||||||
mock_connect.return_value = MagicMock()
|
mock_connect.return_value = MagicMock()
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
with raises(SystemExit) as exc:
|
with raises(SystemExit) as exc:
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
return exc.value.code
|
return exc.value.code
|
||||||
@@ -198,8 +195,6 @@ class TestMainHappyPath:
|
|||||||
worker.run = AsyncMock(side_effect=RuntimeError('boom'))
|
worker.run = AsyncMock(side_effect=RuntimeError('boom'))
|
||||||
mock_prepare_worker.return_value = worker
|
mock_prepare_worker.return_value = worker
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
with raises(SystemExit) as exc:
|
with raises(SystemExit) as exc:
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user