def test_execute():
    docker_compose = DockerComposeExecutor("docker-compose.yml", "pytest123")
    with mock.patch("subprocess.check_output") as check_output:
        docker_compose.execute("up")
        assert check_output.call_args_list == [
            mock.call(
                'docker-compose -f "docker-compose.yml" -p "pytest123" up',
                shell=True,
                stderr=subprocess.STDOUT,
            )
        ]
def test_pypath_compose_files():
    compose_file = py.path.local("/tmp/docker-compose.yml")
    docker_compose = DockerComposeExecutor(compose_file, "pytest123")
    with mock.patch("subprocess.check_output") as check_output:
        docker_compose.execute("up")
        assert check_output.call_args_list == [
            mock.call(
                'docker-compose -f "/tmp/docker-compose.yml"'
                ' -p "pytest123" up',
                shell=True,
                stderr=subprocess.STDOUT,
            )
        ]
예제 #3
0
파일: fixtures.py 프로젝트: rgvanwesep/dvc
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.

    from filelock import FileLock
    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)