From d1fe0ca92df66fedbe54172d4d3e257b3628ebdd Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Mon, 1 Jan 2024 12:12:08 +0100 Subject: [PATCH] Replace sleeps in tests with retries --- tests/integration/test_status.py | 11 ++++++----- tests/integration/test_timelines.py | 15 +++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/integration/test_status.py b/tests/integration/test_status.py index 6f9a2a4..e21518f 100644 --- a/tests/integration/test_status.py +++ b/tests/integration/test_status.py @@ -1,6 +1,7 @@ import json import time import pytest +from tests.utils import run_with_retries from toot import api, cli from toot.exceptions import NotFoundError @@ -46,11 +47,11 @@ def test_favourite(app, user, run): assert result.exit_code == 0 assert result.stdout.strip() == "✓ Status unfavourited" - # A short delay is required before the server returns new data - time.sleep(0.2) - - status = api.fetch_status(app, user, status["id"]).json() - assert not status["favourited"] + def test_favourited(): + nonlocal status + status = api.fetch_status(app, user, status["id"]).json() + assert not status["favourited"] + run_with_retries(test_favourited) def test_favourite_json(app, user, run): diff --git a/tests/integration/test_timelines.py b/tests/integration/test_timelines.py index 1ee3602..818ba3d 100644 --- a/tests/integration/test_timelines.py +++ b/tests/integration/test_timelines.py @@ -1,6 +1,5 @@ import pytest -from time import sleep from uuid import uuid4 from tests.utils import run_with_retries @@ -165,13 +164,14 @@ def test_notifications(app, user, other_user, run): text = f"Paging doctor @{user.username}" status = _post_status(app, other_user, text) - sleep(0.5) # grr - result = run(cli.timelines.notifications) - assert result.exit_code == 0 - assert f"@{other_user.username} mentioned you" in result.stdout - assert status.id in result.stdout - assert text in result.stdout + def test_notifications(): + result = run(cli.timelines.notifications) + assert result.exit_code == 0 + assert f"@{other_user.username} mentioned you" in result.stdout + assert status.id in result.stdout + assert text in result.stdout + run_with_retries(test_notifications) result = run(cli.timelines.notifications, "--mentions") assert result.exit_code == 0 @@ -185,7 +185,6 @@ def test_notifications_follow(app, user, friend_user, run_as): assert result.exit_code == 0 assert f"@{user.username} now follows you" in result.stdout - result = run_as(friend_user, cli.timelines.notifications, "--mentions") assert result.exit_code == 0 assert "now follows you" not in result.stdout