Skip to content

Commit a5cd904

Browse files
authored
fix: ensure container metadata is available (#67)
1 parent 13b56bf commit a5cd904

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/pytest_databases/_service.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,18 @@ def run(
164164
ulimits=ulimits,
165165
mem_limit=mem_limit,
166166
)
167-
container.reload()
167+
168+
# reload the container; sometimes it can take a while before docker
169+
# spins it up and the metadata becomes available, so we're redoing the
170+
# check with a small incremental backup here
171+
for i in range(10):
172+
if any(v for v in container.ports.values()):
173+
break
174+
container.reload()
175+
time.sleep(0.1 + (i / 10))
176+
else:
177+
msg = f"Service {name!r} failed to create container"
178+
raise ValueError(msg)
168179

169180
host_port = int(
170181
container.ports[next(k for k in container.ports if k.startswith(str(container_port)))][0]["HostPort"]

0 commit comments

Comments
 (0)