dvc.testing: fix lockfile in docker_services fixture (#9088)

dvc.testing.docker_services: rollback to previous state

where we were not tearing down the containers
This commit is contained in:
skshetry
2023-02-28 16:54:33 +05:45
committed by GitHub
parent 9f0c4350bd
commit 4a6f3ed64a
2 changed files with 20 additions and 7 deletions
+19 -6
View File
@@ -219,7 +219,16 @@ def docker_compose_project_name():
@pytest.fixture(scope="session")
def docker_services(request, tmp_path_factory):
def docker_services(
tmp_path_factory,
docker_compose_command,
docker_compose_file,
docker_compose_project_name,
docker_setup,
):
from filelock import FileLock
from pytest_docker.plugin import DockerComposeExecutor, Services
if os.environ.get("CI") and os.name == "nt":
pytest.skip("disabled for Windows on CI")
@@ -236,11 +245,15 @@ def docker_services(request, tmp_path_factory):
out = (err.output or b"").decode("utf-8")
pytest.skip(f"docker-compose is not installed: {out}")
from filelock import FileLock
executor = DockerComposeExecutor(
docker_compose_command, 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://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")
# 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(os.fspath(lockfile)):
executor.execute(docker_setup)
# note: we are not tearing down the containers here
return Services(executor)
+1 -1
View File
@@ -97,7 +97,7 @@ tests = [
"flaky",
"pytest<8,>=7",
"pytest-cov",
"pytest-docker",
"pytest-docker>=1,<2",
"pytest-lazy-fixture",
"pytest-mock",
"pytest-test-utils",