0

Suppose I've got a few modules with test cases derived from unittest.TestCase. All those modules reside in one package test:

test/
   test_case1.py
   test_case2.py
   test_case3.py

I'd like to run all tests in all modules in test with one shell command. In order to do it I've added a new module test_all.py, which creates a TestSuite with all the test cases, and main:

def make_suite():
  ... # add test cases explicitly one by one

if __name__ == "__main__":
  suite = make_suite()
  unittest.TextTestRunner().run(suite)

Now I wonder if there is a way to run all the test cases in test without making a TestSuite

Michael
  • 41,026
  • 70
  • 193
  • 341

2 Answers2

4

Starting in Python 2.7, you can do something like this:

python -m unittest discover <test_directory>

Of course, all your test directories must contain an __init__.py file.

You can also use a tool like nose to run your tests.

See also:

Community
  • 1
  • 1
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
1
for f in ./test/test_case*.py; do python $f; done
Bill
  • 57
  • 5