Skip to main content

Python wrapper & utils for the Mountebank over the wire test double tool.

Project description


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


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.4 --production

(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"), 

    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

import pytest
from mbtest import server

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.


Requires make and tox. PyEnv may also come in handy so tests can be run against various Python versions.

Currently, the Makefile targets use Python 3.6 and 3.9 via tox, so a quick-start setup could be:

pip install pyenv tox tox-pyenv
pyenv install 3.6.12 3.9.1
pyenv local 3.6.12 3.9.1

In order to run make test, you'll also need to have Mountebank installed locally:

npm install mountebank@2.4 --production

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


Requires hub, setuptools, wheel and twine. To release version n.n.n, first update the version number in, then:

version="n.n.n" # Needs to match new version number in
git checkout -b "release-$version"
make precommit && git commit -am"Release $version" && git push --set-upstream origin "release-$version" # If not already all pushed, which it should be.
hub release create "V$version" -t"release-$version" -m"Version $version"
python sdist bdist_wheel
twine upload dist/*$version*
git checkout master
git merge "release-$version"

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.10.0.tar.gz (21.9 kB view hashes)

Uploaded source

Built Distribution

mbtest-2.10.0-py3-none-any.whl (24.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page