Skip to main content

Adding unit tests

Unit tests are defined in the deployment function's docstring. The supported test format is a subset of the Python Doctest module.

Here's our example deployment with a description and two unit tests:

def example_doubler(half: int) -> int:
This example deployment doubles numbers!

>>> example_doubler(4)
>>> example_doubler(-20)
if type(half) is not int:
return None
return round(lm.predict([[half]])[0])

Each unit test is two lines. The first is how to call the deployment function, identified by >>>. And the second line is the expected output. Parameters and outputs can be numbers, strings, booleans, dictionaries, or lists.

Here's an example test definition using dictionaries for input and output.

def example_deployment(...):
>>> example_deployment({ "foo": 17, "bar": [1, "two", True] })
{ "baz:": 5.9 }
return ...

Unit tests run during mb.deploy(...) and halt deployments if any test fails. You can also see and run rests in the Tests tab in the Deployment Details page.