我用Python的unittest编写了一个小测试套件:
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))
使用the xmlrunner pacakge将输出格式化为Junit test。在
我添加了一个用于切换JUnit输出的命令行参数:
^{pr2}$问题是不使用--junit
运行脚本可以工作,但是使用--junit
调用它与unittest
的参数冲突:
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()?
您确实应该使用适当的测试运行程序(例如})。在您的特定情况下,我将使用^{} 代替:
nose
或{请注意,我从参数解析器中删除了
help
,因此junit
选项变为隐藏,但它不再干扰unittest.main
。我还将其余参数传递给unittest.main()
。在相关问题 更多 >
编程相关推荐