Skip to main content

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.

made-with-python Continuous Integration Python Versions Licence GitHub all releases GitHub forks GitHub stars GitHub watchers GitHub contributors GitHub issues GitHub issues-closed GitHub pull-requests GitHub pull-requests closed Codacy Badge Codacy Coverage Documentation Status Lines of Code

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

  1. Update version in pyproject.toml (using uv version --bump major|minor|patch), docs/conf.py, and SECURITY.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

  1. Log in to pypi.org and navigate to the mbtest project.
  2. Go to Manage → Publishing.
  3. Under Add a new pending publisher, fill in:
    • PyPI project name: mbtest
    • Owner: brunns
    • Repository name: mbtest
    • Workflow name: release.yml
    • Environment name: pypi
  4. Click Add.

On GitHub

In the repository Settings → Environments, create an environment named pypi. No secrets are needed — OIDC handles authentication automatically.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mbtest-2.16.0.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mbtest-2.16.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file mbtest-2.16.0.tar.gz.

File metadata

  • Download URL: mbtest-2.16.0.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mbtest-2.16.0.tar.gz
Algorithm Hash digest
SHA256 15854363ddd3c50d330e41393a5cec03a091755533fac809b4e476a5c611355c
MD5 6c88c662f328a811718e4037b6fb6626
BLAKE2b-256 5adb899334543a261a051b4a2bdb06ffcb2943aae13e4f40ae5d8a01b0595dd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbtest-2.16.0.tar.gz:

Publisher: release.yml on brunns/mbtest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mbtest-2.16.0-py3-none-any.whl.

File metadata

  • Download URL: mbtest-2.16.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mbtest-2.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fc63c6a2378d82f5ef729728eb4e2f60b3366a08eb2502a61d079bc7af20fe9
MD5 fd7015f2aaf7c5422a4e2e789ef15175
BLAKE2b-256 e36758e5a2c9cad07412ab45ff8220bbf60f8572e1e9ab804379d42886e79827

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbtest-2.16.0-py3-none-any.whl:

Publisher: release.yml on brunns/mbtest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page