Skip to content

Commit a87ef53

Browse files
committed
Return the stopped container instead of an empty list but still give a warning
1 parent dfa08f4 commit a87ef53

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/pytest_docker_compose/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ def __init__(self, docker_project: Project) -> None:
207207
def get(self, key: str) -> Container:
208208
containers = self.docker_project.containers(service_names=[key])
209209
if not containers:
210+
containers = self.docker_project.containers(service_names=[key], stopped=True)
210211
warnings.warn(UserWarning(
211-
"The service %s has no running containers containers" % key
212+
"The service '%s' only has a stopped container, "
213+
"it stopped with '%s'" % (key, containers[0].human_readable_state)
212214
))
213-
return []
214215
container = containers[0]
215216
container.network_info = create_network_info_for_container(container)
216217
return container

tests/pytest_docker_compose_tests/test_module_scoping_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def wait_for_api(module_scoped_container_getter):
2323
assert request_session.get(api_url)
2424

2525
start = time.time()
26-
while module_scoped_container_getter.get("my_short_lived_service"):
26+
while 'Exit' not in module_scoped_container_getter.get("my_short_lived_service").human_readable_state:
2727
if time.time() - start >= 5:
2828
raise RuntimeError(
2929
'my_short_lived_service should spin up, echo "Echoing" and '

0 commit comments

Comments
 (0)