Skip to content

Commit 5b2f843

Browse files
committed
Update coverage
1 parent 6b19f5e commit 5b2f843

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

label_studio/core/tests/test_db_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
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"""
229
import pytest
330
from core.utils.db import batch_delete

0 commit comments

Comments
 (0)