Во время моей первой отважной попытки я подумал: «Если я просто импортирую все свои тестовые модули в файл, а затем вызову эту штуку unittest.main(), она сработает, верно?» Что ж, оказывается, я ошибался.
Код: Выделить всё
import glob
import unittest
testSuite = unittest.TestSuite()
test_file_strings = glob.glob('test_*.py')
module_strings = [str[0:len(str)-3] for str in test_file_strings]
if __name__ == "__main__":
unittest.main()
Код: Выделить всё
$ python all_test.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Код: Выделить всё
import glob
import unittest
testSuite = unittest.TestSuite()
test_file_strings = glob.glob('test_*.py')
module_strings = [str[0:len(str)-3] for str in test_file_strings]
[__import__(str) for str in module_strings]
suites = [unittest.TestLoader().loadTestsFromName(str) for str in module_strings]
[testSuite.addTest(suite) for suite in suites]
print testSuite
result = unittest.TestResult()
testSuite.run(result)
print result
#Ok, at this point I have a result
#How do I display it as the normal unit test command line output?
if __name__ == "__main__":
unittest.main()
Код: Выделить всё
$ python all_test.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK