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

Built distribution (wheel)

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

Total release size: 13.4 kB

Release files / testcontainers_mockserver-9.4.0.tar.gz

Download URL testcontainers_mockserver-9.4.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9ea9db4300570932bcf959fd1cb25b7e96f237e1ef226e288fa69543fa255dc6
BLAKE2b-256 checksum
How to use checksums
d6de865d0a4f04281c60564dc02bb9eb3de0a852d743aca0a2db3b6d05d09d3a
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.4.0-py3-none-any.whl

Download URL testcontainers_mockserver-9.4.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
326ddedef6a5b81e4a0d6abc2ae350ca88b58c9a3f9c8b75a152a85dc5d74e7c
BLAKE2b-256 checksum
How to use checksums
8df05d3c0be2ba26666ab13232730c5706fe8b4b7f1b0f235c410c33abae2e04
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.4.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