Skip to content

Commit bd80e00

Browse files
authored
tests: skip gcsfs and hdfs tests if required modules are not installed (#42)
* tests: skip gcsfs and hdfs tests if required modules are not installed * tests: skip http if required modules are not installed * skip gcfs tests if docker not installed
1 parent f8a9ff5 commit bd80e00

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

upath/tests/conftest.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import os
2+
import shutil
23
import tempfile
34
from pathlib import Path
45
import subprocess
56
import shlex
67
import time
78
import sys
8-
from gcsfs.core import GCSFileSystem
99

1010
import pytest
1111
from fsspec.implementations.local import LocalFileSystem
1212
from fsspec.registry import register_implementation, _registry
1313

1414
import fsspec
15-
import requests
1615

1716

1817
def pytest_addoption(parser):
@@ -85,11 +84,18 @@ def pathlib_base(local_testdir):
8584

8685
@pytest.fixture(scope="session")
8786
def htcluster():
88-
proc = subprocess.Popen(
89-
shlex.split("htcluster startup"),
90-
stderr=subprocess.DEVNULL,
91-
stdout=subprocess.DEVNULL,
92-
)
87+
try:
88+
proc = subprocess.Popen(
89+
shlex.split("htcluster startup"),
90+
stderr=subprocess.DEVNULL,
91+
stdout=subprocess.DEVNULL,
92+
)
93+
except FileNotFoundError as err:
94+
if err.errno == 2 and 'htcluster' == err.filename:
95+
pytest.skip("htcluster not installed")
96+
else:
97+
raise
98+
9399
time.sleep(30)
94100
yield
95101
proc.terminate()
@@ -197,6 +203,11 @@ def docker_gcs():
197203
# assume using real API or otherwise have a server already set up
198204
yield os.environ["STORAGE_EMULATOR_HOST"]
199205
return
206+
207+
requests = pytest.importorskip("requests")
208+
if shutil.which("docker") is None:
209+
pytest.skip("docker not installed")
210+
200211
container = "gcsfs_test"
201212
cmd = (
202213
"docker run -d -p 4443:4443 --name gcsfs_test fsouza/fake-gcs-server:latest -scheme " # noqa: E501
@@ -223,6 +234,11 @@ def docker_gcs():
223234

224235
@pytest.fixture
225236
def gcs(docker_gcs, tempdir, local_testdir, populate=True):
237+
try:
238+
from gcsfs.core import GCSFileSystem
239+
except ImportError:
240+
pytest.skip("gcsfs not installed")
241+
226242
# from gcsfs.credentials import GoogleCredentials
227243
GCSFileSystem.clear_instance_cache()
228244
gcs = fsspec.filesystem("gcs", endpoint_url=docker_gcs)

upath/tests/implementations/test_http.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import pytest # noqa: F401
22

3+
from fsspec import get_filesystem_class
4+
35
from upath import UPath
46
from upath.implementations.http import HTTPPath
57

8+
try:
9+
get_filesystem_class("http")
10+
except ImportError:
11+
pytestmark = pytest.mark.skip
12+
613

714
def test_httppath():
815
path = UPath("http://example.com")

0 commit comments

Comments
 (0)