Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 622
Guglie Avatar asked Jan 24 '26 14:01

Guglie


1 Answers

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.

like image 125
chepner Avatar answered Jan 27 '26 03:01

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!