mbtest
Opinionated Python wrapper & utils for the Mountebank over the wire test double tool.
Includes pytest fixture and PyHamcrest matchers.
Setup
Install with pip:
pip install mbtest
(As usual, use of a venv or virtualenv is recommended.) Also requires Mountebank to have been installed:
npm install mountebank@2.9 --omit=dev
(Alternatively, you can attach to an instance of Mountebank running elsewhere, perhaps in docker.)
Basic example
import requests
from hamcrest import assert_that
from brunns.matchers.response import is_response
from mbtest.matchers import had_request
from mbtest.imposters import Imposter, Predicate, Response, Stub
def test_request_to_mock_server(mock_server):
# Set up mock server with required behavior
imposter = Imposter(Stub(Predicate(path="/test"),
Response(body="sausages")))
with mock_server(imposter):
# Make request to mock server - exercise code under test here
response = requests.get(f"{imposter.url}/test")
assert_that("We got the expected response",
response, is_response().with_status_code(200).and_body("sausages"))
assert_that("The mock server recorded the request",
imposter, had_request().with_path("/test").and_method("GET"))
Needs a pytest fixture, most easily defined in conftest.py:
import pytest
from mbtest import server
@pytest.fixture(scope="session")
def mock_server(request):
return server.mock_server(request)
This will take care of starting and stopping the Mountebank server for you. Examples of more complex predicates can be found in the integration tests.
See the Documentation for more.
Contributing
Requires make, uv, and Node.js (for Mountebank). Integration tests run against an instance of Mountebank running in Docker.
brew install colima docker uv node
colima status || colima start
uv sync --all-groups
npm install mountebank@2.9 --omit=dev
(mbtest is tested against Mountebank versions back as far as 1.16, but obviously only features supported by the Mountebank version you're using will work.)
After that, you should be ready to roll; running make test will let you know if your setup is correct.
Running make precommit tells you if you're OK to commit. For more options, run:
make help
Releasing
- Update version in
pyproject.toml(usinguv version --bump major|minor|patch),docs/conf.py, andSECURITY.md, commit, then:
version=`uv version --short`
git pull -r
make precommit && git commit -am "Release v$version"
git tag "v$version"
git push origin master --tags
Pushing the tag triggers the release workflow, which builds, tests, publishes to PyPI via OIDC, and creates the GitHub release automatically.
PyPI trusted publishing setup
Before the first automated release, a one-time setup is required.
On PyPI
- Log in to pypi.org and navigate to the mbtest project.
- Go to Manage → Publishing.
- Under Add a new pending publisher, fill in:
- PyPI project name:
mbtest - Owner:
brunns - Repository name:
mbtest - Workflow name:
release.yml - Environment name:
pypi
- PyPI project name:
- Click Add.
On GitHub
In the repository Settings → Environments, create an environment named pypi.
No secrets are needed — OIDC handles authentication automatically.
Metadata
Release files for mbtest 2.17.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mbtest-2.17.0.tar.gz | 151.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mbtest-2.17.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 176.7 kB
Release files / mbtest-2.17.0.tar.gz
| Download URL | mbtest-2.17.0.tar.gz |
|---|---|
| Size | 151.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a3fc10d9bd74e054919b42686086e36a6861da99e8f4f0092b6dd41526a5441
|
|
BLAKE2b-256 checksum How to use checksums |
597737e5ef1555126c3622c540aedd92188cf322cf936b2c915d504957cc27cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 3, 2026.
Transparency logRelease files / mbtest-2.17.0-py3-none-any.whl
| Download URL | mbtest-2.17.0-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a343452241c845f74f4c3dd0b9d2d13fd8e6dadfb94cb181914c9b19e5b45c4d
|
|
BLAKE2b-256 checksum How to use checksums |
ab35efae908927eff69b9f44b024f6eef8fcbcc864b2623d35137c3b64bfa6d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 3, 2026.
Transparency log