From 582988ea99d7a05bc314045c15f5f157eba5ccc5 Mon Sep 17 00:00:00 2001 From: Justin Bollinger Date: Fri, 6 Feb 2026 09:43:23 -0500 Subject: [PATCH] test: improve live test to skip gracefully when server unavailable - Add server reachability check before attempting connection - Test skips if Hashview server is not available on localhost:5000 - Prevents test failures when HASHVIEW_TEST_REAL env var is set but server isn't running - Allows test to succeed when Docker/server is available and configured --- tests/test_hashview.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/test_hashview.py b/tests/test_hashview.py index f8abd77..752e426 100644 --- a/tests/test_hashview.py +++ b/tests/test_hashview.py @@ -361,15 +361,29 @@ class TestHashviewAPI: assert "Cookie" in auth_headers or "uuid" in str(auth_headers) assert HASHVIEW_API_KEY in str(auth_headers) - @pytest.mark.skipif( - os.environ.get("HASHVIEW_TEST_REAL", "").lower() not in ("1", "true", "yes"), - reason="Set HASHVIEW_TEST_REAL=1 to run live Hashview list_wordlists test.", - ) def test_list_wordlists_live(self): """Live test for Hashview wordlist listing with auth headers.""" + # Only run this test if explicitly enabled + if os.environ.get("HASHVIEW_TEST_REAL", "").lower() not in ("1", "true", "yes"): + pytest.skip("Set HASHVIEW_TEST_REAL=1 to run live Hashview list_wordlists test.") + hashview_url, hashview_api_key = self._get_hashview_config() if not hashview_url or not hashview_api_key: pytest.skip("Missing hashview_url/hashview_api_key in config.json or env.") + + # Only proceed if the server is actually reachable + try: + import socket + host, port = "127.0.0.1", 5000 + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(2) + result = sock.connect_ex((host, port)) + sock.close() + if result != 0: + pytest.skip(f"Hashview server not reachable at {host}:{port}") + except Exception as e: + pytest.skip(f"Could not check Hashview server availability: {e}") + real_api = HashviewAPI(hashview_url, hashview_api_key) wordlists = real_api.list_wordlists() assert isinstance(wordlists, list)