Skip to content
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
13 changes: 13 additions & 0 deletions core/testcontainers/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def __init__(
for vol in volumes:
self.with_volume_mapping(*vol)

self.tmpfs: dict[str, str] = {}

self.image = image
self._docker = DockerClient(**(docker_client_kw or {}))
self._container: Optional[Container] = None
Expand Down Expand Up @@ -198,6 +200,7 @@ def start(self) -> Self:
ports=cast("dict[int, Optional[int]]", self.ports),
name=self._name,
volumes=self.volumes,
tmpfs=self.tmpfs,
**{**network_kwargs, **self._kwargs},
)

Expand Down Expand Up @@ -270,6 +273,16 @@ def with_volume_mapping(self, host: Union[str, PathLike[str]], container: str, m
self.volumes[str(host)] = mapping
return self

def with_tmpfs_mount(self, container_path: str, size: Optional[str] = None) -> Self:
"""Mount a tmpfs volume on the container.

:param container_path: Container path to mount tmpfs on (e.g., '/data')
:param size: Optional size limit (e.g., '256m', '1g'). If None, unbounded.
:return: Self for chaining
"""
self.tmpfs[container_path] = size or ""
return self

def get_wrapped_container(self) -> "Container":
return self._container

Expand Down
4 changes: 4 additions & 0 deletions modules/mqtt/testcontainers/mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ def start(self, configfile: Optional[str] = None) -> Self:
# default config file
configfile = Path(__file__).parent / MosquittoContainer.CONFIG_FILE
self.with_volume_mapping(configfile, "/mosquitto/config/mosquitto.conf")
# since version 2.1.1 - 2026-02-04, which fixed a PUID/PGID issue, the container needs to write to the data directory,
# so we mount it as tmpfs for better performance in tests
self.with_tmpfs_mount("/data")

# if self.password:
# # TODO: add authentication
# pass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# see https://mosquitto.org/man/mosquitto-conf-5.html

protocol mqtt
user root
listener 1883
log_dest stdout
allow_anonymous true

Expand All @@ -14,7 +13,4 @@ log_timestamp_format %Y-%m-%d %H:%M:%S
persistence true
persistence_location /data/

listener 1883
protocol mqtt

sys_interval 1
2 changes: 1 addition & 1 deletion modules/mqtt/tests/test_mosquitto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from testcontainers.mqtt import MosquittoContainer

VERSIONS = ["1.6.15", "2.0.18"]
VERSIONS = ["1.6.15", "2.0.18", "2.1.2-alpine"]


@pytest.mark.parametrize("version", VERSIONS)
Expand Down
Loading