pythonunit-testingpython-unittest

How to run unittest tests from multiple directories


I have 2 directories containing tests:

project/
|
|-- test/
|    |
|    |-- __init__.py
|    |-- test_1.py
|
|-- my_submodule/
     |
     |-- test/
          |
          |-- __init__.py
          |-- test_2.py

How can I run all tests?

python -m unittest discover . only runs test_1.py

and obviously python -m unittest discover my_submodule only runs test_2.py


Solution

  • unittest currently sees project/my_submodule as an arbitrary directory to ignore, not a package to import. Just add project/my_submodule/__init__.py to change that.