From c9f9a0d2b78d7c1fa8b108f0684743d157b62792 Mon Sep 17 00:00:00 2001 From: Hiren Date: Tue, 3 Mar 2026 00:02:20 -0500 Subject: [PATCH] fix: stabilize test_text_query_word_weights by using component assertions The test was flaky because it relied on exact string matching with specific token ordering. Dict iteration order could cause tokens to appear in different positions across Python versions. Fix: Replace exact string match with component-based assertions that check for expected query parts without relying on ordering. Closes #497 --- tests/unit/test_query_types.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_query_types.py b/tests/unit/test_query_types.py index fa7ad69a..c0f96873 100644 --- a/tests/unit/test_query_types.py +++ b/tests/unit/test_query_types.py @@ -335,7 +335,6 @@ def test_text_query_with_string_filter(): assert "AND" not in query_string_wildcard -@pytest.mark.skip("Test is flaking") def test_text_query_word_weights(): # verify word weights get added into the raw Redis query syntax query = TextQuery( @@ -344,10 +343,19 @@ def test_text_query_word_weights(): text_weights={"alpha": 2, "delta": 0.555, "gamma": 0.95}, ) - assert ( - str(query) - == "@description:(query | string | alpha=>{$weight:2} | bravo | delta=>{$weight:0.555} | tango | alpha=>{$weight:2}) SCORER BM25STD WITHSCORES DIALECT 2 LIMIT 0 10" - ) + # Check query components without relying on exact token ordering + query_str = str(query) + assert "@description:(" in query_str + assert "alpha=>{$weight:2}" in query_str + assert "delta=>{$weight:0.555}" in query_str + assert "query" in query_str + assert "string" in query_str + assert "bravo" in query_str + assert "tango" in query_str + assert "SCORER BM25STD" in query_str + assert "WITHSCORES" in query_str + assert "DIALECT 2" in query_str + assert "LIMIT 0 10" in query_str # raise an error if weights are not positive floats with pytest.raises(ValueError):