Skip to main content

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 to mockserver/mockserver:mockserver-9.0.0.
  • port — Container port MockServer listens on. Defaults to 1080.

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 9.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for testcontainers-mockserver 9.1.0
File Size Uploaded Provenance Actions
testcontainers_mockserver-9.1.0.tar.gz 7.8 kB Without provenance Details for testcontainers_mockserver-9.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for testcontainers-mockserver 9.1.0
File Interpreter ABI Platform Actions
testcontainers_mockserver-9.1.0-py3-none-any.whl Python 3 none any Details for testcontainers_mockserver-9.1.0-py3-none-any.whl

Total release size: 13.4 kB

Release files / testcontainers_mockserver-9.1.0.tar.gz

Download URL testcontainers_mockserver-9.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b35f01a9a3a6c7487db949fff80519145711667367442276d0e74d712d86ae33
BLAKE2b-256 checksum
How to use checksums
7caf7d014f6d6198aafab85b865b81e923dd5637ad6841e99fa00c0c00bbbe79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / testcontainers_mockserver-9.1.0-py3-none-any.whl

Download URL testcontainers_mockserver-9.1.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e5c9afc1569212e4ede3135c19d664bdba8eb24f7f9af467237d44b0a941209
BLAKE2b-256 checksum
How to use checksums
58be5dafc8209249d65551a17c20869e26c5cb86f3366d4766c1252a04f9afbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for testcontainers-mockserver 9.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page