Skip to content
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
10 changes: 9 additions & 1 deletion pytest_docker_tools/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def pytest_runtest_makereport(item, call):
if "request" not in item.funcargs:
return

container_tail = item.funcargs["request"].config.option.container_tail
container_tail = int(container_tail) if container_tail.isdigit() else container_tail
for name, fixturedef in item.funcargs["request"]._fixture_defs.items():
if not hasattr(fixturedef, "cached_result") or not fixturedef.cached_result:
continue
Expand All @@ -39,7 +41,7 @@ def pytest_runtest_makereport(item, call):
rep.sections.append(
(
name + ": " + fixture.name,
fixture.logs(),
fixture.logs(tail=container_tail),
)
)

Expand All @@ -53,3 +55,9 @@ def pytest_addoption(parser):
help="reuse existing containers instead of always creating new ones. Requires the 'name' attribute to be set"
"on container definition",
)
group.addoption(
"--container-tail",
dest="container_tail",
default="all",
help="limit logs of containers",
)
4 changes: 2 additions & 2 deletions pytest_docker_tools/wrappers/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def remove(self, *args, **kwargs):
"Do not remove this container manually. It will be removed automatically by py.test after the test finishes."
)

def logs(self):
return self._container.logs().decode("utf-8")
def logs(self, **kwargs):
return self._container.logs(**kwargs).decode("utf-8")

def get_files(self, path):
"""
Expand Down