I've written a small test suite in Python's 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 output is formatted as Junit test using the xmlrunner pacakge.
I've added a command line argument for toggling JUnit output:
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)
The problem is that running the script without --junit
works, but calling it with --junit
clashes with unittest
's arguments:
option --junit not recognized
Usage: test_lists_of_repos_to_branch.py [options] [test] [...]
Options:
-h, --help Show this message
-v, --verbose Verbose output
...
How can I run a unittest.TestCase without calling unittest.main()?