When running tests from subfolders, import by "full dotted path" rather
than just module name, removing the need to add the test parent folder to
`sys.path`.
This matches CPython more closely, which places `abspath(top)` at the start
of `sys.path` but doesn't include the test file parent dir at all.
It fixes issues where projects may include a `test_xxx.py` file in their
distribution which would (prior to this change) be unintentionally found by
unittest-discover.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Prior to this commit, if no tests were found when running unittest discover
then nothing at all was written to stdout, leading one to think it's not
working at all. CPython unittest does display a "0 tests run" sort of
output in such a case, and this commit ensures this package does the same.
This allows a much more natural way of implementing unitttest-discover:
- unittest provides unittest/__init__.py
- unittest-discover provides unittest/__main__.py
It also fixes an bug where unittest.py previously detected the presence of
unittest-discover.py by importing an checking for the ImportError. But that
could also be raised by a missing dependency. Now when you run
`micropython -m unittest` without unittest-discover, you get
`ImportError: no module named 'unittest.__main__'`, and without the
required deps, `ImportError: no module named 'argparse'`.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
In order to make this more suitable for non-unix ports, the discovery
functionality is moved to a separate 'extension' module which can be
optionally installed.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>