Skip to content

Commit 15e0d18

Browse files
authored
fix: improve test isolation in test_deep_search_no_results (#80)
* fix: improve test isolation in test_deep_search_no_results Expand filtering to catch all test entity prefixes including: - concurrent_test (from parallel test execution) - test_ (common test prefix) - e2e_ (e2e test prefix) - bulk_ (bulk operation tests) Also improve error message to show which helpers were found if assertion fails, making debugging easier. Fixes #79 * fix: address Copilot PR review feedback - Fix comment to include all 5 prefixes (was missing bulk_) - Use startswith() on object_id instead of substring matching to avoid false positives (e.g., sensor.contest_winner) - Changed test_prefixes to tuple for startswith() compatibility - Added explanatory comment with example
1 parent 1c0d131 commit 15e0d18

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

tests/src/e2e/tools/test_deep_search.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,22 @@ async def test_deep_search_no_results(mcp_client):
327327

328328
# Verify we get empty results
329329
# Filter out any test entities that may not have been cleaned up from parallel tests
330-
automations = [a for a in data.get("automations", []) if "deep_search" not in a.get("entity_id", "").lower()]
331-
scripts = [s for s in data.get("scripts", []) if "deep_search" not in s.get("entity_id", "").lower()]
332-
helpers = [h for h in data.get("helpers", []) if "deep_search" not in h.get("entity_id", "").lower()]
330+
# Common test entity prefixes: deep_search, concurrent_test, test_, e2e_, bulk_
331+
test_prefixes = ("deep_search", "concurrent_test", "test_", "e2e_", "bulk_")
332+
333+
def is_test_entity(entity_id: str) -> bool:
334+
"""Check if entity_id appears to be from a test."""
335+
# Extract object_id (part after domain) to avoid false positives
336+
# e.g., "input_text.concurrent_test_3" -> "concurrent_test_3"
337+
object_id = entity_id.lower().split('.')[-1]
338+
return object_id.startswith(test_prefixes)
339+
340+
automations = [a for a in data.get("automations", []) if not is_test_entity(a.get("entity_id", ""))]
341+
scripts = [s for s in data.get("scripts", []) if not is_test_entity(s.get("entity_id", ""))]
342+
helpers = [h for h in data.get("helpers", []) if not is_test_entity(h.get("entity_id", ""))]
333343

334344
assert len(automations) == 0, "Should have no automation matches"
335345
assert len(scripts) == 0, "Should have no script matches"
336-
assert len(helpers) == 0, "Should have no helper matches"
346+
assert len(helpers) == 0, f"Should have no helper matches, but found: {helpers}"
337347

338348
logger.info("✅ Correctly returned empty results for non-matching query")

0 commit comments

Comments
 (0)