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

Built distribution (wheel)

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

Total release size: 13.4 kB

Release files / testcontainers_mockserver-9.2.0.tar.gz

Download URL testcontainers_mockserver-9.2.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dc27c732f49766152f33cb9b8a9d5064c9eccb9e6a070c08e05da9afc1a9a0b5
BLAKE2b-256 checksum
How to use checksums
41bc8870d607bb07af41907f7fa30be93755b9fa00b95a180694840fda791303
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.2.0-py3-none-any.whl

Download URL testcontainers_mockserver-9.2.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af3627e8da311797ac0d2bf8e5caa97362f3eb0f4f79bdd552faf54c0ecbd0b1
BLAKE2b-256 checksum
How to use checksums
ab9e23925a192ff7ea567daa296741eb496d0ac53dd7daa3fd80e9fe4c48cb81
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.2.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