testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Bug: type hint miss match on get_exposed_port

Open MatheusAbdias opened this issue 1 year ago • 0 comments

Describe the bug

A clear and concise description of what the bug is. What did you expect to happen? What happened instead? Method get_exposed_port type miss match:

    @wait_container_is_ready()
    def get_exposed_port(self, port: int) -> str:
        mapped_port = self.get_docker_client().port(self._container.id, port)
        if inside_container():
            gateway_ip = self.get_docker_client().gateway_ip(self._container.id)
            host = self.get_docker_client().host()

            if gateway_ip == host:
                return port
        return mapped_port

mapped_port is int type and port is int type, so this method should return an int.

To Reproduce

Provide a self-contained code snippet that illustrates the bug or unexpected behavior. Ideally, send a Pull Request to illustrate with a test that illustrates the problem.

# settings.py
class Settings(BaseSettings):
    POSTGRES_PORT: int = 5432

# conftest.py
@pytest.fixture(scope="module", autouse=True)
def setup(request):
    postgres.start()

    def remove_container():
        postgres.stop()

    request.addfinalizer(remove_container)
    settings.POSTGRES_PORT = postgres.get_exposed_port(5432) # pylance error type miss match 

Image

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

python: 3.12 testcontainers: 4.8.1 docker: 27.3.1

MatheusAbdias avatar Oct 05 '24 23:10 MatheusAbdias