Skip to content

Commit

Permalink
Remove testcontainers Network compatibility layer (#528)
Browse files Browse the repository at this point in the history
* Revert "Create a compatibility layer to support testing in Python 3.8"

This reverts commit b67ecf8.

* Remove Python 3.8 specific dependency
  • Loading branch information
gwaramadze authored Sep 27, 2024
1 parent c966cb5 commit b2ffaa0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 41 deletions.
9 changes: 0 additions & 9 deletions tests/compat/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions tests/compat/network.py

This file was deleted.

10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Generator

import pytest
from testcontainers.core.network import Network

from .compat import Network
from .containerhelper import ContainerHelper
from .logging import LOGGING_CONFIG, patch_logger_class

Expand Down Expand Up @@ -54,13 +54,13 @@ def schema_registry_container(
) -> Generator[SchemaRegistryContainer, None, None]:
container, schema_registry_address = (
ContainerHelper.create_schema_registry_container(
kafka_container.internal_broker_address
network, kafka_container.internal_broker_address
)
)
test_logger.debug(
f"Starting Schema Registry container on {schema_registry_address}"
)
ContainerHelper.start_schema_registry_container(container, network)
ContainerHelper.start_schema_registry_container(container)
test_logger.debug(f"Started Schema Registry container on {schema_registry_address}")
yield SchemaRegistryContainer(schema_registry_address=schema_registry_address)
container.stop()
Expand All @@ -73,9 +73,9 @@ def factory():
kafka_container,
internal_broker_address,
external_broker_address,
) = ContainerHelper.create_kafka_container()
) = ContainerHelper.create_kafka_container(network)
test_logger.debug(f"Starting Kafka container on {external_broker_address}")
ContainerHelper.start_kafka_container(kafka_container, network)
ContainerHelper.start_kafka_container(kafka_container)
test_logger.debug(f"Started Kafka container on {external_broker_address}")
yield KafkaContainer(
broker_address=external_broker_address,
Expand Down
15 changes: 6 additions & 9 deletions tests/containerhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
from typing import Tuple

from testcontainers.core.container import DockerContainer

from .compat import Network
from testcontainers.core.network import Network


class ContainerHelper:
@staticmethod
def create_kafka_container() -> Tuple[DockerContainer, str, str]:
def create_kafka_container(network: Network) -> Tuple[DockerContainer, str, str]:
"""
Returns (kafka container, internal broker address, external broker address) tuple
"""
Expand Down Expand Up @@ -50,19 +49,18 @@ def create_kafka_container() -> Tuple[DockerContainer, str, str]:
.with_env("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "1")
.with_env("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR", "1")
.with_bind_ports(kafka_port, kafka_port)
.with_network(network)
)
return kafka_container, internal_broker_address, external_broker_address

@staticmethod
def start_kafka_container(
kafka_container: DockerContainer, network: Network
) -> None:
def start_kafka_container(kafka_container: DockerContainer) -> None:
kafka_container.start()
network.connect(kafka_container.get_wrapped_container().id)
wait_for_container_readiness(kafka_container, "Kafka Server started")

@staticmethod
def create_schema_registry_container(
network: Network,
broker_address: str,
) -> Tuple[DockerContainer, str]:
docker_image_name = "confluentinc/cp-schema-registry"
Expand All @@ -79,16 +77,15 @@ def create_schema_registry_container(
.with_env("SCHEMA_REGISTRY_LISTENERS", schema_registry_address)
.with_env("SCHEMA_REGISTRY_HOST_NAME", "localhost")
.with_bind_ports(schema_registry_port, schema_registry_port)
.with_network(network)
)
return schema_registry_container, schema_registry_address

@staticmethod
def start_schema_registry_container(
schema_registry_container: DockerContainer,
network: Network,
) -> None:
schema_registry_container.start()
network.connect(schema_registry_container.get_wrapped_container().id)
wait_for_container_readiness(
schema_registry_container, "Server started, listening for requests"
)
Expand Down
3 changes: 1 addition & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
testcontainers==3.7.1; python_version < '3.9'
testcontainers==4.8.1; python_version >= '3.9'
testcontainers==4.8.1
pytest
requests>=2.32
docker>=7.1.0 # Required to use requests>=2.32
Expand Down

0 comments on commit b2ffaa0

Please sign in to comment.