I have Python unit test code organized as follows:
Maindir
|
|--Dir1
| |
| |-- test_A.py
| |-- test_B.py
| |-- test_C.py
|
|--Dir2
| ...
I assume you get the picture. In each of the Dirx
directories I have a file named suite.py
which puts together a suite of tests from the tests in the give directory (so you can choose specific test, omit other tests, etc.). These files look e.g. like the following (in case to choose all tests, they might also select only a subset of tests) [also consider test <-> unit test]:
import test_A
import test_B
import test_C
suite1 = test.TestSuite()
suite1.addTests(test.TestLoader().loadTestsFromTestCase(test_A.MyTest))
suite1.addTests(test.TestLoader().loadTestsFromTestCase(test_B.MyTest))
suite1.addTests(test.TestLoader().loadTestsFromTestCase(test_C.MyTest))
The main runner, execall.py
, in the Maindir
directory looks like this:
from Dir1.suite import suite1
from Dir2.suite import suite2
suite_all = test.TestSuite([
suite1,
suite2])
if __name__ == '__main__':
test.main(defaultTest='suite_all')
Now I can do the following:
- Run all tests: 'execall.py' (as documented)
- Run a specific suite:
execall.py suite1
(as documented)
But how can I run only a specific single test? And how can I run all tests of the specific file? I tried the following without success, with the same error: 'TestSuite' object has no attribute 'xxx'
execall.py suite1.test_A
execall.py suite1.test_A.test1
execall.py test_A
execall.py test_A.test1
execall.py -h
gives very specific examples of how to run single tests or tests in testcases, but in my case this does not seem to work.