From 19038b32bd7b531e02e04c56aa10877ce3dad7bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Feb 2023 12:57:31 +0545 Subject: [PATCH] build(deps-dev): unpin pytest-docker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix docker fixtures and unpin pytest-docker * git_server: mount volume to different /custom-cont-init.d --------- Co-authored-by: Saugat Pachhai (सौगात) --- dvc/testing/fixtures.py | 56 +++++++++++++------------------------ pyproject.toml | 4 +-- tests/docker-compose.yml | 2 +- tests/remotes/git_server.py | 3 +- 4 files changed, 25 insertions(+), 40 deletions(-) diff --git a/dvc/testing/fixtures.py b/dvc/testing/fixtures.py index 0518ebf4f..ad6589193 100644 --- a/dvc/testing/fixtures.py +++ b/dvc/testing/fixtures.py @@ -26,8 +26,6 @@ __all__ = [ "workspace", "make_workspace", "local_workspace", - "docker", - "docker_compose", "docker_compose_project_name", "docker_services", ] @@ -215,48 +213,34 @@ def local_workspace(make_workspace): return make_workspace("workspace", typ="local") -@pytest.fixture(scope="session") -def docker(): - # See https://travis-ci.community/t/docker-linux-containers-on-windows/301 - if os.environ.get("CI") and os.name == "nt": - pytest.skip("disabled for Windows on Github Actions") - - try: - subprocess.check_output("docker ps", shell=True) - except (subprocess.CalledProcessError, OSError): - pytest.skip("no docker installed") - - -@pytest.fixture(scope="session") -def docker_compose(docker): # noqa: ARG001 - try: - subprocess.check_output("docker-compose version", shell=True) - except (subprocess.CalledProcessError, OSError): - pytest.skip("no docker-compose installed") - - @pytest.fixture(scope="session") def docker_compose_project_name(): return "pytest-dvc-test" @pytest.fixture(scope="session") -def docker_services(docker_compose_file, docker_compose_project_name, tmp_path_factory): - # overriding `docker_services` fixture from `pytest_docker` plugin to - # only launch docker images once. +def docker_services(request, tmp_path_factory): + if os.environ.get("CI") and os.name == "nt": + pytest.skip("disabled for Windows on CI") + + try: + subprocess.check_output("docker ps", stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as err: + out = (err.output or b"").decode("utf-8") + pytest.skip(f"docker is not installed or the daemon is not running: {out}") + + try: + cmd = "docker-compose version" + subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as err: + out = (err.output or b"").decode("utf-8") + pytest.skip(f"docker-compose is not installed: {out}") from filelock import FileLock - # pylint: disable-next=import-error - from pytest_docker.plugin import DockerComposeExecutor, Services - - executor = DockerComposeExecutor(docker_compose_file, docker_compose_project_name) - # making sure we don't accidentally launch docker-compose in parallel, # as it might result in network conflicts. Inspired by: - # https://github.com/pytest-dev/pytest-xdist#making-session-scoped-fixtures-execute-only-once - lockfile = tmp_path_factory.getbasetemp().parent / "docker-compose.lock" - with FileLock(str(lockfile)): # pylint:disable=abstract-class-instantiated - executor.execute("up --build -d") - - return Services(executor) + # https://pytest-xdist.readthedocs.io/en/stable/how-to.html#making-session-scoped-fixtures-execute-only-once + root = tmp_path_factory.getbasetemp().parent + with FileLock(os.fspath(root / "docker-compose.lock")): + yield request.getfixturevalue("docker_services") diff --git a/pyproject.toml b/pyproject.toml index f24bb2faf..81fae8bdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -97,12 +97,12 @@ tests = [ "flaky", "pytest<8,>=7", "pytest-cov", - "pytest-docker==0.13", + "pytest-docker", "pytest-lazy-fixture", "pytest-mock", "pytest-test-utils", "pytest-timeout>=2", - "pytest-xdist>=3.1", + "pytest-xdist>=3", 'pywin32>=225; sys_platform == "win32"', # optional test dependency ] webdav = ["dvc-webdav==2.19.1"] diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 51233e820..818544416 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -10,4 +10,4 @@ services: - 2222 volumes: - ./remotes/user.key.pub:/tmp/key - - ./remotes/git-init:/config/custom-cont-init.d + - ./remotes/git-init:/custom-cont-init.d diff --git a/tests/remotes/git_server.py b/tests/remotes/git_server.py index 402146beb..77a288b2e 100644 --- a/tests/remotes/git_server.py +++ b/tests/remotes/git_server.py @@ -9,11 +9,12 @@ class GitSSH(SSH): @pytest.fixture -def git_server(test_config, docker_compose, docker_services): +def git_server(request, test_config): import asyncssh from sshfs import SSHFileSystem test_config.requires("ssh") + docker_services = request.getfixturevalue("docker_services") conn_info = { "host": "127.0.0.1", "port": docker_services.port_for("git-server", 2222),