run_single.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. import unittest
  2. from io import StringIO
  3. import argparse
  4. import importlib
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument("suite", help="the name of the test suite from which a "
  7. "class should be profiled",
  8. type=str)
  9. args = parser.parse_args()
  10. if not args.suite:
  11. print("A test suite must be provided")
  12. else:
  13. mod_name = "cloudbridge.test.test_{}_service".format(args.suite)
  14. case_name = "Cloud{}ServiceTestCase".format("".join([x.capitalize() for
  15. x in
  16. args.suite.split('_')]))
  17. case_name = case_name.replace("VmType", "VMType").replace("CloudCloud",
  18. "Cloud")
  19. if "interface" in mod_name or "cycle" in mod_name or "_cloud" in mod_name:
  20. mod_name = mod_name.replace("_service", "")
  21. case_name = case_name.replace("Service", "")
  22. print("{}.{}\n\n".format(mod_name, case_name))
  23. case = getattr(importlib.import_module(mod_name), case_name)
  24. stream = StringIO()
  25. runner = unittest.TextTestRunner(stream=stream)
  26. result = runner.run(unittest.makeSuite(case))
  27. stream.seek(0)
  28. print('Test output\n', stream.read())