示例#1
0
 def run(self):  # pylint: disable=E0202
     """ invoked by the command """
     tests = unittest.TestLoader().discover('src/test', pattern='test*.py')
     result = XMLTestRunner(output='test-reports').run(tests)
     if result.wasSuccessful():
         return 0
     return 1
示例#2
0
def main():
    from unittest import TestLoader, TestSuite
    from xmlrunner import XMLTestRunner

    import db_checks

    suites = [
        TestLoader().loadTestsFromTestCase(db_checks.Test),
    ]

    tests_results_dir = "test-reports-python"
    result = XMLTestRunner(output=tests_results_dir).run(TestSuite(suites))
    if not result.wasSuccessful():
        sys.exit(1)
示例#3
0
class testResult(object):
    def __init__(self, testClass):
        self.cTest = testClass
        self.outLogFile = self.cTest.get_out_path('test_result.log')

    def runTest(self, isSilent=False):
        '''
        if isSilent is False then sys.stderr will be used as output of result.
        Otherwise output will be saved to the file.
        Read documentation of TextTestRunner for more information.
        '''
        paramDic = {'stream': None, 'verbosity': 2, 'output': 'test-reports'}
        if isSilent:
           paramDic['stream'] = open(self.outLogFile, 'w')
        suite = unittest.TestLoader().loadTestsFromTestCase(self.cTest)
        self.result = XMLTestRunner(**paramDic).run(suite)
        if paramDic['stream']:
           paramDic['stream'].close()
        self.checkResult(isSilent)

    def checkResult(self, isSilent=False):
        '''
        Value of isSilent is processed conversely to the runTest method.
        if isSilent is False then output will be saved to the file.
        Otherwise output will be printed to the sys.stderr.
        '''
        if self.result.wasSuccessful():
           return

        myOutFile = sys.stderr
        if not isSilent:
           myOutFile = open(self.outLogFile, 'w')

        if self.result.errors:
           print('ERRORS:', sep='\n', end='\n', file=myOutFile)
        for r in self.result.errors:
           print(*r, sep='\n', end='\n', file=myOutFile)

        if self.result.failures:
           print('FAILURES:', sep='\n', end='\n', file=myOutFile)
        for r in self.result.failures:
           print(*r, sep='\n', end='\n', file=myOutFile)
        myOutFile.close()
示例#4
0
  # setting up logging
  log_opt = args['logging']
  logger = logging.getLogger(globals.LOGGER_NAME)
  if log_opt == 'INFO':
    logger.level = logging.INFO
  elif log_opt == 'DEBUG':
    logger.level = logging.DEBUG

  test_context = TestContext(
      ENGINE_DIRECTORY, DATA_DIRECTORY,
      args['eventserver_ip'], int(args['eventserver_port']))

  tests_dict = get_tests(test_context)
  test_names = args['tests']
  tests = []
  if test_names is not None:
    tests = [t for name, t in tests_dict.items() if name in test_names]
  else:
    tests = tests_dict.values()

  # Actual tests execution
  event_server_process = srun_bg('pio eventserver --ip {} --port {}'
      .format(test_context.es_ip, test_context.es_port))
  time.sleep(5)
  result = XMLTestRunner(verbosity=2, output='test-reports').run(
                unittest.TestSuite(tests))
  event_server_process.kill()

  if not result.wasSuccessful():
    sys.exit(1)
        logger.level = logging.INFO
    elif log_opt == 'DEBUG':
        logger.level = logging.DEBUG

    test_context = TestContext(ENGINE_DIRECTORY, DATA_DIRECTORY,
                               args['eventserver_ip'],
                               int(args['eventserver_port']))

    tests_dict = get_tests(test_context)
    test_names = args['tests']
    tests = []
    if test_names is not None:
        tests = [t for name, t in tests_dict.items() if name in test_names]
    else:
        tests = tests_dict.values()

    # Actual tests execution
    es_wait_time = 25
    logger.info(
        "Starting eventserver and waiting {}s for it to initialize".format(
            es_wait_time))
    event_server_process = srun_bg('pio eventserver --ip {} --port {}'.format(
        test_context.es_ip, test_context.es_port))
    time.sleep(es_wait_time)
    result = XMLTestRunner(verbosity=2, output='test-reports').run(
        unittest.TestSuite(tests))
    event_server_process.kill()

    if not result.wasSuccessful():
        sys.exit(1)