Welcome to mbtest’s documentation#

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

Includes pytest fixture and PyHamcrest matchers.


Install from Pypi as usual, using pip , tox, or setup.py.

Also requires Mountebank to have been installed:

$ npm install mountebank@2.6 --production


A 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 conftest.py:

import pytest
from mbtest import server

def mock_server(request):
    return server.mock_server(request)

Indices and tables#