Skip to content

Commit 7ae4b60

Browse files
committed
chore(run-unit-tests): auto-set rootless podman env vars for container tests
When the runner discovers at least one container-based test, it now defaults `DOCKER_HOST` to the rootless podman socket and `TESTCONTAINERS_RYUK_DISABLED` to `true` (Ryuk is incompatible with rootless podman). Already-set values are preserved, so users running on a real docker host or with a different podman socket override are not affected. Both `python tools/run-unit-tests` and the `python tools/run-container-tests` wrapper benefit; CONTRIBUTING already documented the env vars as a manual prerequisite, and a "lightweight wrapper" was flagged as future work.
1 parent 5e9569c commit 7ae4b60

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tools/run-unit-tests

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@ def is_container_test(check_plugins, plugin):
7979
return any(sig in content for sig in CONTAINER_TEST_SIGNATURES)
8080

8181

82+
def ensure_podman_env():
83+
"""Pre-flight environment setup for testcontainers under rootless podman.
84+
85+
Sets `DOCKER_HOST` to the rootless podman socket and disables the
86+
Ryuk reaper container, but only when those variables are not already
87+
set by the caller. Without this the testcontainers-python library
88+
either falls back to the docker socket (which doesn't exist on a
89+
podman-only host) or hangs trying to start a Reaper container that
90+
rootless podman cannot reach.
91+
"""
92+
if 'DOCKER_HOST' not in os.environ:
93+
sock = f'unix:///run/user/{os.getuid()}/podman/podman.sock'
94+
os.environ['DOCKER_HOST'] = sock
95+
print(f'note: DOCKER_HOST not set, defaulting to {sock}', file=sys.stderr)
96+
if 'TESTCONTAINERS_RYUK_DISABLED' not in os.environ:
97+
os.environ['TESTCONTAINERS_RYUK_DISABLED'] = 'true'
98+
print(
99+
'note: TESTCONTAINERS_RYUK_DISABLED not set, defaulting to true '
100+
'(Ryuk reaper is incompatible with rootless podman)',
101+
file=sys.stderr,
102+
)
103+
104+
82105
def main():
83106
"""Find and run unit tests, report results."""
84107
parser = argparse.ArgumentParser(description=__doc__.strip().split('\n\n')[0])
@@ -128,6 +151,12 @@ def main():
128151
print('No unit tests found.')
129152
sys.exit(0)
130153

154+
# If any of the discovered tests will spin up a container, set the
155+
# rootless-podman env vars so the user does not have to remember
156+
# them. Already-set values are preserved.
157+
if any(is_container_test(check_plugins, p) for p in plugins):
158+
ensure_podman_env()
159+
131160
passed = []
132161
failed = []
133162
total = len(plugins)

0 commit comments

Comments
 (0)