unittest usage with micropython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
mikhail
Posts: 2
Joined: Sat Sep 01, 2018 2:22 am

unittest usage with micropython

Post by mikhail » Sat Sep 01, 2018 2:36 am

I have some experience with using standard unittest library with Python3.6 on PC. But it seems like uPy version of this library is a bit different. (https://github.com/micropython/micropyt ... r/unittest)

If I place my test_project.py in the same directory with my main project, I can run my tests in rshell using

repl ~ unittest.main('test_project') ~

But when I place my test_project.py in a directory named tests which contains __init__.py and test_project.py unittest can't discover my tests when I try command:

repl ~ unittest.main('tests.test_project') ~

I'd like to place all my tests in dedicated directory because otherwise there are too much clutter in /flash/. How can I achieve that? Thanks.

SpotlightKid
Posts: 380
Joined: Wed Apr 08, 2015 5:19 am

Re: unittest usage with micropython

Post by SpotlightKid » Sat Sep 01, 2018 10:57 am

untitest.main uses dir(module) to discover tests. So importing all your tests in tests/__init__.py would probably work, i.e.;

Code: Select all

from .test_foo import *
from .test_bar import *
...

mikhail
Posts: 2
Joined: Sat Sep 01, 2018 2:22 am

Re: unittest usage with micropython

Post by mikhail » Sun Sep 02, 2018 5:38 am

Thank you. It seems it works. I run my test using:

repl ~ import unittest ~ unittest.main('tests') ~

Post Reply