Repository: iterative/dvc-s3 (language: python)

Issue:
migrate to pytest-servers
https://github.com/iterative/pytest-servers


Discussion / hints:

Fix patch:
diff --git a/setup.cfg b/setup.cfg
index 5c91b5b..1492b07 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -44,6 +44,7 @@ tests =
     pytest-mock==3.6.1
     pytest-lazy-fixture==0.6.3
     pytest-docker==0.10.3
+    pytest-servers[s3]==0.1.4
     flaky==3.7.0
     mock==4.0.3
     wget==3.2


Test patch:
diff --git a/dvc_s3/tests/cloud.py b/dvc_s3/tests/cloud.py
index 78c749d..2ead252 100644
--- a/dvc_s3/tests/cloud.py
+++ b/dvc_s3/tests/cloud.py
@@ -7,16 +7,12 @@
 from funcy import cached_property
 
 TEST_AWS_REPO_BUCKET = os.environ.get("DVC_TEST_AWS_REPO_BUCKET", "dvc-temp")
-TEST_AWS_ENDPOINT_URL = "http://127.0.0.1:{port}/"
 
 
 class S3(Cloud, CloudURLInfo):
-
-    TEST_AWS_ENDPOINT_URL = None
-
     @property
     def config(self):
-        return {"url": self.url, "endpointurl": self.TEST_AWS_ENDPOINT_URL}
+        return {"url": self.url}
 
     @staticmethod
     def _get_storagepath():
@@ -81,3 +77,23 @@ def read_text(self, encoding=None, errors=None):
     @property
     def fs_path(self):
         return self.bucket + "/" + self.path.lstrip("/")
+
+
+class FakeS3(S3):
+    """Fake S3 client that is supposed to be using a mock server's endpoint"""
+
+    def __init__(self, *args, endpoint_url: str, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.endpoint_url = endpoint_url
+
+    def __truediv__(self, key):
+        ret = super().__truediv__(key)
+        ret.endpoint_url = self.endpoint_url
+        return ret
+
+    @property
+    def config(self):
+        return {"url": self.url, "endpointurl": self.endpoint_url}
+
+    def get_url(self):  # pylint: disable=arguments-differ
+        return str(self)
diff --git a/dvc_s3/tests/docker-compose.yml b/dvc_s3/tests/docker-compose.yml
deleted file mode 100644
index 8474d1d..0000000
--- a/dvc_s3/tests/docker-compose.yml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-version: '3.2'
-services:
-  motoserver:
-    image: motoserver/moto
-    ports:
-      - "5000"
diff --git a/dvc_s3/tests/fixtures.py b/dvc_s3/tests/fixtures.py
index 4159d79..8e4ec6d 100644
--- a/dvc_s3/tests/fixtures.py
+++ b/dvc_s3/tests/fixtures.py
@@ -1,80 +1,20 @@
-import os
-
 import pytest
 
-from .cloud import S3, TEST_AWS_ENDPOINT_URL, TEST_AWS_REPO_BUCKET
-
-
-@pytest.fixture
-def s3_fake_creds_file(monkeypatch):
-    # https://github.com/spulec/moto#other-caveats
-    import pathlib
-
-    aws_dir = pathlib.Path("~").expanduser() / ".aws"
-    aws_dir.mkdir(exist_ok=True)
-
-    aws_creds = aws_dir / "credentials"
-    initially_exists = aws_creds.exists()
-
-    if not initially_exists:
-        aws_creds.touch()
-
-    try:
-        with monkeypatch.context() as m:
-            m.setenv("AWS_ACCESS_KEY_ID", "testing")
-            m.setenv("AWS_SECRET_ACCESS_KEY", "testing")
-            m.setenv("AWS_SECURITY_TOKEN", "testing")
-            m.setenv("AWS_SESSION_TOKEN", "testing")
-            yield
-    finally:
-        if aws_creds.exists() and not initially_exists:
-            aws_creds.unlink()
-
-
-@pytest.fixture(scope="session")
-def docker_compose_file():
-    return os.path.join(os.path.dirname(__file__), "docker-compose.yml")
-
-
-@pytest.fixture(scope="session")
-def s3_server(
-    docker_compose, docker_services
-):  # pylint: disable=unused-argument
-    import requests
-
-    port = docker_services.port_for("motoserver", 5000)
-    endpoint_url = TEST_AWS_ENDPOINT_URL.format(port=port)
-
-    def _check():
-        try:
-            r = requests.get(endpoint_url, timeout=10)
-            return r.ok
-        except requests.RequestException:
-            return False
-
-    docker_services.wait_until_responsive(
-        timeout=60.0, pause=0.1, check=_check
-    )
-    S3.TEST_AWS_ENDPOINT_URL = endpoint_url
-    return endpoint_url
+from .cloud import S3, FakeS3
 
 
 @pytest.fixture
 # pylint: disable-next=redefined-outer-name,unused-argument
-def make_s3(s3_server, s3_fake_creds_file):
+def make_s3(tmp_s3_path, s3_server):
     def _make_s3():
-        s3dir = S3(S3.get_url())
-        s3dir._s3.create_bucket(  # pylint: disable=protected-access
-            Bucket=TEST_AWS_REPO_BUCKET
-        )
-        return s3dir
+        return FakeS3(str(tmp_s3_path).rstrip("/"), endpoint_url=s3_server)
 
     return _make_s3
 
 
 @pytest.fixture
 def s3(make_s3):  # pylint: disable=redefined-outer-name
-    return make_s3()
+    yield make_s3()
 
 
 @pytest.fixture