Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo command line option #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/lovely/pytest/docker/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class Services(object):
https://github.com/AndreLouisCaron/pytest-docker
"""

def __init__(self, compose_files, docker_ip, project_name='pytest'):
def __init__(self, compose_files, docker_ip, project_name='pytest', echo=False):
self._docker_compose = DockerComposeExecutor(
compose_files, project_name
compose_files, project_name, echo
)
self._services = {}
self.docker_ip = docker_ip
Expand Down Expand Up @@ -143,9 +143,10 @@ def wait_until_responsive(check, timeout, pause,


class DockerComposeExecutor(object):
def __init__(self, compose_files, project_name):
def __init__(self, compose_files, project_name, echo=False):
self._compose_files = compose_files
self._project_name = project_name
self.echo = echo

def execute(self, *subcommand):
command = ["docker-compose"]
Expand All @@ -155,6 +156,10 @@ def execute(self, *subcommand):
command.append('-p')
command.append(self._project_name)
command += subcommand

if self.echo:
print(" ".join(command))

return execute(command)


Expand Down Expand Up @@ -199,10 +204,12 @@ def docker_services(request, docker_compose_files, docker_ip, docker_services_pr
The services will be stopped after all tests are run.
"""
keep_alive = request.config.getoption("--keepalive", False)
echo = request.config.getoption("--docker-echo", False)
services = Services(
docker_compose_files,
docker_ip,
docker_services_project_name
docker_services_project_name,
echo
)
yield services
if not keep_alive:
Expand All @@ -214,5 +221,8 @@ def pytest_addoption(parser):

Add the --keepalive option for pytest.
"""
parser.addoption("--keepalive", "-K", action="store_true",
group = parser.getgroup("lovely-pytest-docker")
group.addoption("--keepalive", "-K", action="store_true",
default=False, help="Keep docker containers alive")
group.addoption("--docker-echo", action="store_true",
default=False, help="Print commands being run")