mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
build(deps-dev): unpin pytest-docker
* fix docker fixtures and unpin pytest-docker * git_server: mount volume to different /custom-cont-init.d --------- Co-authored-by: Saugat Pachhai (सौगात) <[email protected]>
This commit is contained in:
co-authored by
Saugat Pachhai
parent
648edd71eb
commit
19038b32bd
+20
-36
@@ -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")
|
||||
|
||||
+2
-2
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user