From 0902af020cf34e70ed57a90ec77c8249babf2609 Mon Sep 17 00:00:00 2001 From: Sascha Klawohn <sascha.klawohn@physik.hu-berlin.de> Date: Fri, 21 Mar 2025 17:40:01 +0100 Subject: [PATCH] Tweak group owner test retry --- tests/app/v1/routers/test_groups.py | 4 +++- tests/utils.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/app/v1/routers/test_groups.py b/tests/app/v1/routers/test_groups.py index 2073b21104..ef0ba7f05e 100644 --- a/tests/app/v1/routers/test_groups.py +++ b/tests/app/v1/routers/test_groups.py @@ -224,7 +224,9 @@ def test_owner_not_member(auth_headers, client, group_molds, group_owner_not_mem group.reload_without_clean() return group.owner in group.members - assert check_with_retry(condition) + assert check_with_retry(condition, retries=10, delay0=0.2), ( + 'group in db not updated within expected time' + ) @pytest.mark.parametrize( diff --git a/tests/utils.py b/tests/utils.py index 18f8c6db63..732fa79b87 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -206,9 +206,10 @@ def dict_to_params(d): def check_with_retry(condition_func, retries=5, delay0=0.1): + """Call function, return early on truthy result. Retry with increasing delays.""" for attempt in range(retries): - if condition_func(): - return True + if result := condition_func(): + return result time.sleep(delay0 * (attempt + 1)) -- GitLab