Python wrapper & utils for the Mountebank over the wire test double tool.
Project description
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 the version number in pyproject.toml, commit, then:
version="n.n.n"
git checkout -b "release-$version"
make precommit && git commit -am"Release $version" && git push --set-upstream origin "release-$version"
git tag "v$version" && git push origin "v$version"
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mbtest-2.15.0.tar.gz.
File metadata
- Download URL: mbtest-2.15.0.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
889d6a97991085ba3ab65acb235c473193772e3ac8d0c318d55d128536cc9205
|
|
| MD5 |
61fed37bc337b872428cb48ae654a6c3
|
|
| BLAKE2b-256 |
329e8919873686c9b9bac472f633ec31dba8d4c758c0beb87d6f661cee7257c3
|
Provenance
The following attestation bundles were made for mbtest-2.15.0.tar.gz:
Publisher:
release.yml on brunns/mbtest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mbtest-2.15.0.tar.gz -
Subject digest:
889d6a97991085ba3ab65acb235c473193772e3ac8d0c318d55d128536cc9205 - Sigstore transparency entry: 997256113
- Sigstore integration time:
-
Permalink:
brunns/mbtest@13f8916e6d6f469bcc919b27910aa079a803308b -
Branch / Tag:
refs/tags/v2.15.0 - Owner: https://github.com/brunns
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@13f8916e6d6f469bcc919b27910aa079a803308b -
Trigger Event:
push
-
Statement type:
File details
Details for the file mbtest-2.15.0-py3-none-any.whl.
File metadata
- Download URL: mbtest-2.15.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d215a97521e0e09a4c15110ed68a5b51315b4a38281c2f278a142996873da4f2
|
|
| MD5 |
dd79473956b9230df1a9202215011c56
|
|
| BLAKE2b-256 |
2de4a3ce3ec43d80927749604f691925fa43321de96964c2274f23674c5450c3
|
Provenance
The following attestation bundles were made for mbtest-2.15.0-py3-none-any.whl:
Publisher:
release.yml on brunns/mbtest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mbtest-2.15.0-py3-none-any.whl -
Subject digest:
d215a97521e0e09a4c15110ed68a5b51315b4a38281c2f278a142996873da4f2 - Sigstore transparency entry: 997256116
- Sigstore integration time:
-
Permalink:
brunns/mbtest@13f8916e6d6f469bcc919b27910aa079a803308b -
Branch / Tag:
refs/tags/v2.15.0 - Owner: https://github.com/brunns
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@13f8916e6d6f469bcc919b27910aa079a803308b -
Trigger Event:
push
-
Statement type: