This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

Writing tests

Tests in MicroPython are located at the path tests/. The following is a listing of key directories and the runner script:

 ├── basics
 ├── extmod
 ├── float
 ├── micropython

There are subfolders maintained to categorize the tests. Add a test by creating a new file in one of the existing folders or in a new folder. It’s also possible to make custom tests outside this tests folder, which would be recommended for a custom port.

For example, add the following code in a file in the tests/unix/ subdirectory:

def print_one():


If you run your tests, this test should appear in the test output:

$ cd ports/unix
$ make tests
skip  unix/
pass  unix/
pass  unix/
pass  unix/
pass  unix/
pass  unix/
pass  unix/

Tests are run by comparing the output from the test target against the output from CPython. So any test should use print statements to indicate test results.

For tests that can’t be compared to CPython (i.e. micropython-specific functionality), you can provide a .py.exp file which will be used as the truth for comparison.

The other way to run tests, which is useful when running on targets other than the Unix port, is:

$ cd tests
$ ./

Then to run on a board:

$ ./ --target minimal --device /dev/ttyACM0

And to run only a certain set of tests (eg a directory):

$ ./ -d basics
$ ./ float/builtin*.py