From cf7959ab1616c78843b5987a632ceb9060ccc480 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 29 Jul 2019 23:15:26 -0400 Subject: [PATCH] Attempt to fix randomly failing tests (#1071) * Fix flaky tests that require redis which were occasionally failing --- tests/utils/test_events.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/utils/test_events.py b/tests/utils/test_events.py index f0d7e9e0..e3bc9bcb 100644 --- a/tests/utils/test_events.py +++ b/tests/utils/test_events.py @@ -97,11 +97,12 @@ def test_redis_event_manager_installed(): try: app = create_ctfd(config=RedisConfig) + except ConnectionError: + print("Failed to connect to redis. Skipping test.") + else: with app.app_context(): assert isinstance(app.events_manager, RedisEventManager) destroy_ctfd(app) - except ConnectionError: - print("Failed to connect to redis. Skipping test.") def test_redis_event_manager_subscription(): @@ -114,6 +115,9 @@ def test_redis_event_manager_subscription(): try: app = create_ctfd(config=RedisConfig) + except ConnectionError: + print("Failed to connect to redis. Skipping test.") + else: with app.app_context(): saved_data = { u"data": { @@ -144,8 +148,6 @@ def test_redis_event_manager_subscription(): assert message.__str__().startswith("event:notification\ndata:") break destroy_ctfd(app) - except ConnectionError: - print("Failed to connect to redis. Skipping test.") def test_redis_event_manager_publish(): @@ -158,6 +160,9 @@ def test_redis_event_manager_publish(): try: app = create_ctfd(config=RedisConfig) + except ConnectionError: + print("Failed to connect to redis. Skipping test.") + else: with app.app_context(): saved_data = { "user_id": None, @@ -173,5 +178,3 @@ def test_redis_event_manager_publish(): event_manager = RedisEventManager() event_manager.publish(data=saved_data, type="notification", channel="ctf") destroy_ctfd(app) - except ConnectionError: - print("Failed to connect to redis. Skipping test.")