testcontainers-mockserver
A Testcontainers module for MockServer in Python.
Starts a mockserver/mockserver Docker container, waits for readiness, and provides
convenient accessors for the mapped host, port, and URL.
Installation
pip install testcontainers-mockserver
Usage
from testcontainers_mockserver import MockServerContainer
import requests
with MockServerContainer() as mockserver:
url = mockserver.get_url() # e.g. "http://localhost:49152"
# Create an expectation
requests.put(f"{url}/mockserver/expectation", json={
"httpRequest": {"method": "GET", "path": "/hello"},
"httpResponse": {"statusCode": 200, "body": "world"},
})
# Match it
resp = requests.get(f"{url}/hello")
assert resp.text == "world"
API
MockServerContainer(image=..., port=1080)
image— Docker image to use. Defaults tomockserver/mockserver:mockserver-7.5.0.port— Container port MockServer listens on. Defaults to1080.
Methods
| Method | Returns | Description |
|---|---|---|
get_client() |
MockServerClient |
A cached, ready-wired mockserver client pointed at the mapped host/port |
get_url() |
str |
HTTP base URL (e.g. http://localhost:49152) |
get_secure_url() |
str |
HTTPS base URL (same port, https:// scheme) |
get_host() |
str |
Mapped host IP |
get_port() |
int |
Mapped host port |
with_server_port(port) |
self |
Override the listen port |
with_log_level(level) |
self |
Set MOCKSERVER_LOG_LEVEL |
with_property(key, value) |
self |
Set any MockServer env var |
with_initialization_json(path) |
self |
Point to a startup expectations JSON file |
Building and Testing
# Install in editable mode with test dependencies
pip install -e .[test]
# Run unit tests (no Docker needed)
pytest tests/test_container_config.py
# Run all tests including integration (requires Docker)
pytest
# Skip Docker-dependent tests
pytest -m "not docker"
Requirements
- Python >= 3.9
- Docker (for integration tests and actual usage)
testcontainers>= 4.0.0
Metadata
Release files for testcontainers-mockserver 7.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| testcontainers_mockserver-7.6.0.tar.gz | 7.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| testcontainers_mockserver-7.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.1 kB
Release files / testcontainers_mockserver-7.6.0.tar.gz
| Download URL | testcontainers_mockserver-7.6.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71922890356b71e92aeb9f74081a8826078273751d118c9eb016f6238c1d2eb6
|
|
BLAKE2b-256 checksum How to use checksums |
7570bea4a41aa3d0199a8feeba87920a5095fe9560fe47a8e2998395c2671a56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / testcontainers_mockserver-7.6.0-py3-none-any.whl
| Download URL | testcontainers_mockserver-7.6.0-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cedaa2a9e8acb4680254208535502d16286034b0ddf1954748caf22c3daf9ed1
|
|
BLAKE2b-256 checksum How to use checksums |
7ef46bace1d2a3f6e562b49dee60b959f129d1dd12b00ad18e22c7641d2f4a70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|