Use with Docker#

If you want to use your own mountebank service instance (Docker, for example) you have no need to use npm requirements.

docker run -p 2525:2525 -p IMPOSTER_PORT:IMPOSTER_PORT -d bbyars/mountebank

You can do like this in your []:

import pytest
from mbtest.server import MountebankServer

def mock_server():
    return MountebankServer(port=2525, host="localhost")

Don’t forget to open docker ports for mountebank (default 2525) and for each of its imposters.

from mbtest.imposters import Imposter, Predicate, Response, Stub

imposter = Imposter(
        Predicate(path="/test") & Predicate(query={}) & Predicate(method="GET"),

with mock_server(imposter) as ms:
    response = requests.get(f"{imposter.url}/test")
    # Check your request
    assert_that(imposter, had_request().with_path("/test").and_method("GET"))

If you don’t specify a port for the Imposter it will be allocated randomly.


You can combine your Predicates with &(and), |(or).