Python: How to run unittest.main() for all source files in a subdirectory?

As of Python 2.7, test discovery is automated in the unittest package. From the docs:

Unittest supports simple test discovery. In order to be compatible
with test discovery, all of the test files must be modules or packages
importable from the top-level directory of the project (this means
that their filenames must be valid identifiers).

Test discovery is implemented in TestLoader.discover(), but can also
be used from the command line. The basic command-line usage is:

cd project_directory
python -m unittest discover

By default it looks for packages named test*.py, but this can be changed so you might use something like

python -m unittest discover --pattern=*.py

In place of your test.py script.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)