From 1a096a775e13b8b2c6f90d706a5805cb047a6372 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 14 Apr 2021 23:00:07 +0200 Subject: test: skip if configured search server is not reachable --- tests/test_matching.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/test_matching.py b/tests/test_matching.py index 48f7b3a..8d70d15 100644 --- a/tests/test_matching.py +++ b/tests/test_matching.py @@ -13,11 +13,25 @@ settings = Dynaconf(envvar_prefix="FUZZYCAT") FATCAT_SEARCH_URL = settings.get("FATCAT_SEARCH_URL", "https://search.fatcat.wiki:443") +def is_not_reachable(url, timeout=3): + return not is_reachable(url) + +def is_reachable(url, timeout=3): + """ + Return true, if URL is reachable and returns HTTP 200. + """ + try: + return requests.get(url, verify=False, timeout=timeout).ok + except Exception: + return False + @pytest.fixture def es_client(): return elasticsearch.Elasticsearch([FATCAT_SEARCH_URL]) +@pytest.mark.skipif(is_not_reachable(FATCAT_SEARCH_URL), + reason="{} not reachable, use e.g. FUZZYCAT_FATCAT_SEARCH_URL=localhost:9200 to override".format(FATCAT_SEARCH_URL)) def test_match_release_fuzzy(es_client, caplog): cases = ( ("wtv64ahbdzgwnan7rllwr3nurm", 1), -- cgit v1.2.3