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

Feature container logs #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/htmlcov/
/pytest_docker.egg-info/
/src/pytest_docker.egg-info/
build
dist
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ responds over HTTP::
timeout=30.0, pause=0.1,
check=lambda: is_responsive(url)
)
return url
yield url

# Optionally print/log container logs for debugging.
for line in docker_services.get_logs('abc').split('\n'):
log.debug(line)

def test_something(some_http_service):
"""Sample test."""
Expand Down
6 changes: 6 additions & 0 deletions src/pytest_docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def wait_until_responsive(self, check, timeout, pause,
'Timeout reached while waiting on service!'
)

def get_logs(self, service):
"""Fetches the logs of the container of the specified service.

Use `get_logs.split('\n')` to parse log by line."""
return self._docker_compose.execute('logs {}'.format(service))


def str_to_list(arg):
if isinstance(arg, (list, tuple)):
Expand Down