Skip to content

fix(core): multiple container start invocations with custom labels #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
15 changes: 9 additions & 6 deletions core/testcontainers/core/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ def create_labels(image: str, labels: Optional[dict[str, str]]) -> dict[str, str
if k.startswith(TESTCONTAINERS_NAMESPACE):
raise ValueError("The org.testcontainers namespace is reserved for internal use")

labels[LABEL_LANG] = "python"
labels[LABEL_TESTCONTAINERS] = "true"
labels[LABEL_VERSION] = importlib.metadata.version("testcontainers")
tc_labels = {
**labels,
LABEL_LANG: "python",
LABEL_TESTCONTAINERS: "true",
LABEL_VERSION: importlib.metadata.version("testcontainers"),
}

if image == c.ryuk_image:
return labels
return tc_labels

labels[LABEL_SESSION_ID] = SESSION_ID
return labels
tc_labels[LABEL_SESSION_ID] = SESSION_ID
return tc_labels
7 changes: 7 additions & 0 deletions core/tests/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ def test_session_are_module_import_scoped():
assert LABEL_SESSION_ID in first_labels
assert LABEL_SESSION_ID in second_labels
assert first_labels[LABEL_SESSION_ID] == second_labels[LABEL_SESSION_ID]


def test_create_no_side_effects():
input_labels = {"key": "value"}
expected_labels = input_labels.copy()
create_labels("not-ryuk", {"key": "value"})
assert input_labels == expected_labels, input_labels
Loading