Я написал небольшой тестовый набор в UnitTest Пайтона:Python: запустить unittest.TestCase без вызова unittest.main()?
class TestRepos(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Get repo lists from the svn server."""
...
def test_repo_list_not_empty(self):
"""Assert the the repo list is not empty"""
self.assertTrue(len(TestRepoLists.all_repos)>0)
def test_include_list_not_empty(self):
"""Assert the the include list is not empty"""
self.assertTrue(len(TestRepoLists.svn_dirs)>0)
...
if __name__ == '__main__':
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='tests',
descriptions=True))
Выход в формате тест Junit с использованием the xmlrunner pacakge.
Я добавил аргумент командной строки для переключения вывода JUnit:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Validate repo lists.')
parser.add_argument('--junit', action='store_true')
args=parser.parse_args()
print args
if (args.junit):
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='tests',
descriptions=True))
else:
unittest.main(TestRepoLists)
Проблема заключается в том, что запуск сценария без --junit
работ, но называть его --junit
столкновений с аргументами unittest
«s:
option --junit not recognized
Usage: test_lists_of_repos_to_branch.py [options] [test] [...]
Options:
-h, --help Show this message
-v, --verbose Verbose output
...
Как я могу запустить unittest.TestCase без вызова unittest.main()?
'Файл '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", строка 93, в __init__ self. progName = os.path.basename (argv [0]) IndexError: индекс индекса вне диапазона –
@AdamMatan: обновлено; 'main()' ожидает полный argv, я думаю. –
Спасибо за исправление. Он работает с '--junit', но без него я получаю« Ran 0 тестов в 0.000s ». –