testcontainers / testcontainers/testcontainers-python

Provide generic DockerContainer with init attributes

未关闭
#236 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

✅ close on merge 📦 package: core 🚀 enhancement
主要语言
Python
星标
2.3k
派生
386
平均合并
4 小时 40 分钟
30 天内合并 PR
1

描述

First I want to thank you for this very nice and convenient library.

Background

I am using the library for smoke tests for microservices. In these tests I spin up a container and make sure I can e.g., fetch an endpoint and see that the container is built and starts correctly.

The library provides all convenient methods, except for a way to set e.g., ports and env variables in the context manager. To solve this I have subclassed testcontainers.core.container.DockerContainer into a class as below:

from typing import Any

import testcontainers.core.container

class ContainerContext(testcontainers.core.container.DockerContainer):
    def __init__(
        self, image: str, ports: list[int], env_vars: dict[str, str], **kwargs: Any
    ) -> None:
        super().__init__(image, **kwargs)

        self.with_exposed_ports(*ports)
        for env, value in env_vars.items():
            self.with_env(env, value)

and use it as

import requests

def test_smoke():
    with container_context(
        "my_service_image",
        ports=[8000],
        env_vars={"SOME_ENV_SETTINGS": "some_value", "SOME_ENV_SETTINGS2": "other_value"},
    ) as con:
        r = requests.get(
            f"http://{con.get_container_host_ip()}:{con.get_exposed_port(8000)}"
        )
        assert r

Proposal

  • Include a generic container class where all name, ports, env, volumes, … can be set as init variables.

I saw #114 that removed the previous GenericContainer but I don't see a motivation why it was done and why it could not be extended.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

检查 testcontainers.core.container.DockerContainer 以及 #114 中讨论过的 GenericContainer 移除方案。将请求的初始化属性——name、ports、env 和 volumes——与现有的容器 API 进行比较;当通用容器无需创建子类即可在初始化时配置这些值时,即可认为该提案完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
docker, python
领域
devops, testing
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。