Skip to content

Commit 7a573f2

Browse files
committed
refactor: extract caplog assertion helper to reduce duplication
Add assert_warning_logged helper function to reduce code duplication in warning assertion patterns across multiple test methods.
1 parent 3a4eed6 commit 7a573f2

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

tests/integration/test_multi_field_sorting_integration.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
from tests.conftest import skip_if_redis_version_below
1010

1111

12+
def assert_warning_logged(caplog, message_fragment):
13+
"""Helper to assert that a warning containing the message fragment was logged.
14+
15+
Args:
16+
caplog: pytest caplog fixture
17+
message_fragment: String fragment to search for in log messages
18+
"""
19+
assert any(
20+
message_fragment in record.message for record in caplog.records
21+
), f"Expected warning containing '{message_fragment}' to be logged"
22+
23+
1224
@pytest.fixture
1325
def products_schema():
1426
"""Create a schema for product data with multiple sortable fields."""
@@ -179,13 +191,8 @@ def test_multiple_fields_uses_first_only(self, products_index, caplog):
179191
results = products_index.query(query)
180192

181193
# Check that warning was logged
182-
assert any(
183-
"Multiple sort fields specified" in record.message
184-
for record in caplog.records
185-
), "Should log warning about multiple fields"
186-
assert any(
187-
"Using first field: 'price'" in record.message for record in caplog.records
188-
), "Should indicate which field is being used"
194+
assert_warning_logged(caplog, "Multiple sort fields specified")
195+
assert_warning_logged(caplog, "Using first field: 'price'")
189196

190197
# Verify only first field (price) is used for sorting
191198
assert len(results) > 0
@@ -204,10 +211,7 @@ def test_multiple_fields_mixed_format(self, products_index, caplog):
204211
results = products_index.query(query)
205212

206213
# Check warning
207-
assert any(
208-
"Multiple sort fields specified" in record.message
209-
for record in caplog.records
210-
)
214+
assert_warning_logged(caplog, "Multiple sort fields specified")
211215

212216
# Verify first field (stock) is used - ascending order
213217
assert len(results) > 0
@@ -283,13 +287,8 @@ def test_vector_query_multiple_fields_warning(self, products_index, caplog):
283287
results = products_index.query(query)
284288

285289
# Check warning
286-
assert any(
287-
"Multiple sort fields specified" in record.message
288-
for record in caplog.records
289-
)
290-
assert any(
291-
"Using first field: 'rating'" in record.message for record in caplog.records
292-
)
290+
assert_warning_logged(caplog, "Multiple sort fields specified")
291+
assert_warning_logged(caplog, "Using first field: 'rating'")
293292

294293
# Verify first field (rating) is used
295294
assert len(results) > 0
@@ -340,10 +339,7 @@ def test_text_query_multiple_fields(self, products_index, caplog):
340339
results = products_index.query(query)
341340

342341
# Check warning
343-
assert any(
344-
"Multiple sort fields specified" in record.message
345-
for record in caplog.records
346-
)
342+
assert_warning_logged(caplog, "Multiple sort fields specified")
347343

348344
# Should use first field (price ASC)
349345
if len(results) > 0:

0 commit comments

Comments
 (0)