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.
unittest usage with micropython
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: unittest usage with micropython
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
Thank you. It seems it works. I run my test using:
repl ~ import unittest ~ unittest.main('tests') ~
repl ~ import unittest ~ unittest.main('tests') ~