Skip to content

Commit

Permalink
Merge pull request #42 from sensein/tst/skip-no-cxn
Browse files Browse the repository at this point in the history
TST: Skip connection dependent tests when no connection is present
  • Loading branch information
yarikoptic authored Oct 13, 2023
2 parents 7b51165 + 760803b commit 88adc39
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion etelemetry/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
from ..client import _etrequest, get_project, check_available_version


def check_cxn(scope="session"):
import requests

try:
requests.get("http://example.com")
return True
except Exception:
return False


no_cxn = check_cxn() is False


@pytest.mark.skipif(no_cxn, reason="No connection")
def test_etrequest():
endpoint = "http://fakeendpoint/"
with pytest.raises(RuntimeError):
Expand All @@ -16,6 +30,7 @@ def test_etrequest():
assert _etrequest(endpoint)


@pytest.mark.skipif(no_cxn, reason="No connection")
def test_get_project():
repo = "invalidrepo"
with pytest.raises(ValueError):
Expand All @@ -27,8 +42,9 @@ def test_get_project():

def test_noet():
import os

old_var = None
if 'NO_ET' in os.environ:
if "NO_ET" in os.environ:
old_var = (True, os.environ["NO_ET"])
os.environ["NO_ET"] = "1"
repo = "github/hub"
Expand All @@ -40,6 +56,7 @@ def test_noet():
os.environ["NO_ET"] = old_var[1]


@pytest.mark.skipif(no_cxn, reason="No connection")
def test_check_available():
repo = "invalidrepo"
res = check_available_version(repo, "0.1.0")
Expand Down

0 comments on commit 88adc39

Please sign in to comment.