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.2.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.3.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.3.0
File Size Uploaded Provenance Actions
testcontainers_mockserver-9.3.0.tar.gz 7.8 kB Without provenance Details for testcontainers_mockserver-9.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 13.4 kB

Release files / testcontainers_mockserver-9.3.0.tar.gz

Download URL testcontainers_mockserver-9.3.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6a949daf949a9fac202d124cae3cbe674e7ad0e38af2a6ecb25a3ce504f7b92f
BLAKE2b-256 checksum
How to use checksums
b6f234a28d5297b960c3e4bdb1665886d5d6f7cdab58a8d9b237a15e182441dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

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

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

Security for testcontainers-mockserver 9.3.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