Testcontainers module for MockServer
Project description
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.1.0.port— Container port MockServer listens on. Defaults to1080.
Methods
| Method | Returns | Description |
|---|---|---|
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file testcontainers_mockserver-7.1.0.tar.gz.
File metadata
- Download URL: testcontainers_mockserver-7.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3723fee03e46d2412ed30735bf58b82979df9ebafc6d76ed56395c4a2d425560
|
|
| MD5 |
8a28319ab59280558c922dc91a8342a1
|
|
| BLAKE2b-256 |
b7f03d3651dee2b3ed863d06a79cbd3ab5b1a4d48c76336c3062a7278b5b5d6c
|
File details
Details for the file testcontainers_mockserver-7.1.0-py3-none-any.whl.
File metadata
- Download URL: testcontainers_mockserver-7.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
656d7685cd870357a794e51e6300b38fa93a822e4a1d3f2ee25acc5eabe7030c
|
|
| MD5 |
41a14e05ef9f79b20612e19c1324d0a3
|
|
| BLAKE2b-256 |
a445041bb3c3f98bc9ce5d559d07fcdf43e50d66745955ba1e78e33de0500ad4
|