From a12f6055646713244b41aae61864a70d30cd1531 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Mon, 18 Aug 2025 13:32:13 +0200 Subject: [PATCH] Deflake test_collection.py Current tests perform read operations twice and assert based on previous results. This approach is inherently flaky because some background operations in Splunk can modify data between reads. This change, wraps every test case in assertEventuallyTrue. --- tests/test_collection.py | 159 ++++++++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 62 deletions(-) diff --git a/tests/test_collection.py b/tests/test_collection.py index 5055ea593..baa71a4ac 100755 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -82,61 +82,77 @@ def test_metadata(self): ) def test_list(self): - for coll_name in collections: + def test(coll_name): coll = getattr(self.service, coll_name) expected = [ent.name for ent in coll.list(count=10, sort_mode="auto")] - if len(expected) == 0: - logging.debug(f"No entities in collection {coll_name}; skipping test.") found = [ent.name for ent in coll.list()][:10] - self.assertEqual( - expected, - found, - msg=f"on {coll_name} (expected: {expected}, found: {found})", - ) + if expected != found: + logging.warning( + f"on {coll_name} (expected: {expected}, found: {found})", + ) + return False + + return True - def test_list_with_count(self): - N = 5 for coll_name in collections: + self.assertEventuallyTrue(lambda: test(coll_name)) + + def test_list_with_count(self): + def test(coll_name): + N = 5 coll = getattr(self.service, coll_name) expected = [ent.name for ent in coll.list(count=N + 5)][:N] N = len(expected) # in case there are