I would like to write tests for the micropython code I am writing for the micro:bit. The examples here use doctest. I am open to work arounds for any testing system.
Working python example called testing_python.py:
def sum(a, b):
'''
>>> sum(3, 0)
3
'''
return a + b
print(sum(2,2))
When I test using:
python -m doctest -v testing_python.py
I get:
4
Trying:
sum(3, 0)
Expecting:
3
ok
Failing example using micropython for the micro:bit called testing_micropython.py:
from microbit import *
def sum(a, b):
'''
>>> sum(3, 0)
3
'''
return a + b
print(sum(2,2))
When I test using:
python -m doctest -v testing_micropython.py
I get
Traceback (most recent call last):
...
ModuleNotFoundError: No module named 'microbit'
I tried wrapping the 'import microbit' statement in a try, except clause. This will make this simple example work. However, when I start using any of the other non-python library functions found in the micro:bit library, such as Image or utime, then the doctest will fail again.