Page 1 of 1

unittest usage with micropython

Posted: Sat Sep 01, 2018 2:36 am
by mikhail
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.

Re: unittest usage with micropython

Posted: Sat Sep 01, 2018 10:57 am
by SpotlightKid
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 *
...

Re: unittest usage with micropython

Posted: Sun Sep 02, 2018 5:38 am
by mikhail
Thank you. It seems it works. I run my test using:

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