Skip to content

Commit aabbce7

Browse files
fix(python): skip Docker container management when WIREMOCK_URL is set (fern-api#13625)
fix(python): skip Docker container management when WIREMOCK_URL is set When WIREMOCK_URL environment variable is already set (e.g., by a CI/CD pipeline providing an external WireMock sidecar container), skip starting and stopping the Docker container. This matches the behavior of the PHP, Ruby, and Rust SDK generators.
1 parent 989e425 commit aabbce7

6 files changed

Lines changed: 86 additions & 5 deletions

File tree

generators/python-v2/sdk/src/wire-tests/WireTestSetupGenerator.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ import subprocess
384384
import pytest
385385
386386
_STARTED: bool = False
387+
_EXTERNAL: bool = False # True when using an external WireMock instance (skip container lifecycle)
387388
_WIREMOCK_URL: str = "http://localhost:8080" # Default, will be updated after container starts
388389
_PROJECT_NAME: str = "${projectName}"
389390
@@ -410,10 +411,19 @@ def _get_wiremock_port() -> str:
410411
411412
def _start_wiremock() -> None:
412413
"""Starts the WireMock container using docker-compose."""
413-
global _STARTED, _WIREMOCK_URL
414+
global _STARTED, _EXTERNAL, _WIREMOCK_URL
414415
if _STARTED:
415416
return
416417
418+
# If WIREMOCK_URL is already set (e.g., by CI/CD pipeline), skip container management
419+
existing_url = os.environ.get("WIREMOCK_URL")
420+
if existing_url:
421+
_WIREMOCK_URL = existing_url
422+
_EXTERNAL = True
423+
_STARTED = True
424+
print(f"\\nUsing external WireMock at {_WIREMOCK_URL} (container management skipped)")
425+
return
426+
417427
print(f"\\nStarting WireMock container (project: {_PROJECT_NAME})...")
418428
try:
419429
subprocess.run(
@@ -434,6 +444,10 @@ def _start_wiremock() -> None:
434444
435445
def _stop_wiremock() -> None:
436446
"""Stops and removes the WireMock container."""
447+
if _EXTERNAL:
448+
# Container is managed externally; nothing to tear down.
449+
return
450+
437451
print("\\nStopping WireMock container...")
438452
subprocess.run(
439453
["docker", "compose", "-f", _COMPOSE_FILE, "-p", _PROJECT_NAME, "down", "-v"],

generators/python/sdk/versions.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# yaml-language-server: $schema=../../../fern-versions-yml.schema.json
22
# For unreleased changes, use unreleased.yml
3+
- version: 5.0.3
4+
changelogEntry:
5+
- summary: |
6+
Skip Docker container management in generated `tests/conftest.py` when the
7+
`WIREMOCK_URL` environment variable is already set. This allows wire tests to
8+
run in CI/CD pipelines that provide an external WireMock sidecar container
9+
without requiring Docker-in-Docker support.
10+
type: fix
11+
createdAt: "2026-03-17"
12+
irVersion: 65
13+
314
- version: 5.0.2
415
changelogEntry:
516
- summary: |

seed/python-sdk/exhaustive/no-custom-config/tests/conftest.py

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/python-sdk/exhaustive/wire-tests-custom-client-name/tests/conftest.py

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/python-sdk/python-streaming-parameter-openapi/with-wire-tests/tests/conftest.py

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/python-sdk/server-sent-events/with-wire-tests/tests/conftest.py

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)