File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ import logging
2+
3+ from label_studio .core .utils import db as db_utils
4+
5+
6+ class _BrokenConnection :
7+ vendor = 'testdb'
8+
9+ @property
10+ def settings_dict (self ):
11+ # Simulate an unexpected error when accessing connection.settings_dict
12+ raise RuntimeError ('boom' )
13+
14+
15+ def test_current_db_key_exception_path (monkeypatch , caplog ):
16+ # Arrange: replace connection with a broken one to trigger the except path
17+ monkeypatch .setattr (db_utils , 'connection' , _BrokenConnection ())
18+
19+ # Act: call current_db_key and capture error logs
20+ with caplog .at_level (logging .ERROR , logger = 'label_studio.core.utils.db' ):
21+ key = db_utils .current_db_key ()
22+
23+ # Assert: name fallback used and error message logged
24+ assert key == 'testdb:unknown'
25+ assert any ('Error getting current DB key' in rec .message for rec in caplog .records )
26+
27+
128"""This module contains tests for database utility functions in core/utils/db.py"""
229import pytest
330from core .utils .db import batch_delete
You can’t perform that action at this time.
0 commit comments