Exemplo n.º 1
0
 def _catch_test_status(self, method):
     """Wrapper around test methods for catching and logging failures."""
     try:
         method()
         if self.__log_warn_used:
             raise exceptions.TestWarn("Test passed but there were warnings "
                                       "during execution. Check the log for "
                                       "details.")
     except exceptions.TestBaseException as detail:
         self.__status = detail.status
         self.__fail_class = detail.__class__.__name__
         self.__fail_reason = astring.to_text(detail)
         self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
     except AssertionError as detail:
         self.__status = 'FAIL'
         self.__fail_class = detail.__class__.__name__
         self.__fail_reason = astring.to_text(detail)
         self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
     except Exception as detail:  # pylint: disable=W0703
         self.__status = 'ERROR'
         tb_info = stacktrace.tb_info(sys.exc_info())
         self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
         try:
             self.__fail_class = astring.to_text(detail.__class__.__name__)
             self.__fail_reason = astring.to_text(detail)
         except TypeError:
             self.__fail_class = "Exception"
             self.__fail_reason = ("Unable to get exception, check the "
                                   "traceback for details.")
         for e_line in tb_info:
             self.log.error(e_line)
Exemplo n.º 2
0
    def run_test(self, test_factory, queue):
        """
        Run a test instance in a subprocess.

        :param instance: Test instance.
        :type instance: :class:`avocado.test.Test` instance.
        :param queue: Multiprocess queue.
        :type queue: :class`multiprocessing.Queue` instance.
        """
        def timeout_handler(signum, frame):
            e_msg = "Timeout reached waiting for %s to end" % instance
            raise exceptions.TestTimeoutError(e_msg)

        def interrupt_handler(signum, frame):
            e_msg = "Test %s interrupted by user" % instance
            raise exceptions.TestInterruptedError(e_msg)

        sys.stdout = output.LoggingFile(
            logger=logging.getLogger('avocado.test.stdout'))
        sys.stderr = output.LoggingFile(
            logger=logging.getLogger('avocado.test.stderr'))

        try:
            instance = self.job.test_loader.load_test(test_factory)
            if instance.runner_queue is None:
                instance.runner_queue = queue
            runtime.CURRENT_TEST = instance
            early_state = instance.get_state()
            queue.put(early_state)
        except Exception:
            exc_info = sys.exc_info()
            app_logger = logging.getLogger('avocado.app')
            app_logger.exception('Exception loading test')
            tb_info = stacktrace.tb_info(exc_info)
            queue.put({'load_exception': tb_info})
            return

        signal.signal(signal.SIGUSR1, timeout_handler)
        signal.signal(signal.SIGINT, interrupt_handler)

        self.result.start_test(early_state)
        try:
            instance.run_avocado()
        finally:
            queue.put(instance.get_state())
Exemplo n.º 3
0
    def _run_test(self, test_factory, queue):
        """
        Run a test instance.

        :param test_factory: Test factory (test class and parameters).
        :type test_factory: tuple of :class:`avocado.test.Test` and dict.
        :param queue: Multiprocess queue.
        :type queue: :class`multiprocessing.Queue` instance.
        """
        def timeout_handler(signum, frame):
            e_msg = "Timeout reached waiting for %s to end" % instance
            raise exceptions.TestTimeoutError(e_msg)

        def interrupt_handler(signum, frame):
            e_msg = "Test %s interrupted by user" % instance
            raise exceptions.TestInterruptedError(e_msg)

        sys.stdout = output.LoggingFile(logger=logging.getLogger('avocado.test.stdout'))
        sys.stderr = output.LoggingFile(logger=logging.getLogger('avocado.test.stderr'))

        try:
            instance = self.job.test_loader.load_test(test_factory)
            if instance.runner_queue is None:
                instance.runner_queue = queue
            runtime.CURRENT_TEST = instance
            early_state = instance.get_state()
            queue.put(early_state)
        except Exception:
            exc_info = sys.exc_info()
            app_logger = logging.getLogger('avocado.app')
            app_logger.exception('Exception loading test')
            tb_info = stacktrace.tb_info(exc_info)
            queue.put({'load_exception': tb_info})
            return

        signal.signal(signal.SIGUSR1, timeout_handler)
        signal.signal(signal.SIGINT, interrupt_handler)

        self.result.start_test(early_state)
        try:
            instance.run_avocado()
        finally:
            queue.put(instance.get_state())
Exemplo n.º 4
0
    def run_avocado(self):
        """
        Wraps the run method, for execution inside the avocado runner.

        :result: Unused param, compatibility with :class:`unittest.TestCase`.
        """
        self._setup_environment_variables()
        try:
            self._tag_start()
            self._run_avocado()
        except exceptions.TestBaseException as detail:
            self.__status = detail.status
            self.__fail_class = detail.__class__.__name__
            self.__fail_reason = astring.to_text(detail)
            self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
        except AssertionError as detail:
            self.__status = 'FAIL'
            self.__fail_class = detail.__class__.__name__
            self.__fail_reason = astring.to_text(detail)
            self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
        except Exception as detail:  # pylint: disable=W0703
            self.__status = 'ERROR'
            tb_info = stacktrace.tb_info(sys.exc_info())
            self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
            try:
                self.__fail_class = astring.to_text(detail.__class__.__name__)
                self.__fail_reason = astring.to_text(detail)
            except TypeError:
                self.__fail_class = "Exception"
                self.__fail_reason = ("Unable to get exception, check the "
                                      "traceback for details.")
            for e_line in tb_info:
                self.log.error(e_line)
        finally:
            if self.__sysinfo_enabled:
                self.__sysinfo_logger.end(self.__status)
            self.__phase = 'FINISHED'
            self._tag_end()
            self._report()
            self.log.info("")
            self._stop_logging()
Exemplo n.º 5
0
 try:
     self.tag_start()
     self.run(result)
 except exceptions.TestBaseException, detail:
     self.status = detail.status
     self.fail_class = detail.__class__.__name__
     self.fail_reason = detail
     self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
 except AssertionError, detail:
     self.status = 'FAIL'
     self.fail_class = detail.__class__.__name__
     self.fail_reason = detail
     self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
 except Exception, detail:
     self.status = 'FAIL'
     tb_info = stacktrace.tb_info(sys.exc_info())
     self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
     try:
         self.fail_class = str(detail.__class__.__name__)
         self.fail_reason = str(detail)
     except TypeError:
         self.fail_class = "Exception"
         self.fail_reason = ("Unable to get exception, check the "
                             "traceback for details.")
     for e_line in tb_info:
         self.log.error(e_line)
 finally:
     self.tag_end()
     self.report()
     self.log.info("")
     with open(self.logfile, 'r') as log_file_obj:
Exemplo n.º 6
0
 try:
     self.tag_start()
     self.run(result)
 except exceptions.TestBaseException, detail:
     self.status = detail.status
     self.fail_class = detail.__class__.__name__
     self.fail_reason = detail
     self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
 except AssertionError, detail:
     self.status = 'FAIL'
     self.fail_class = detail.__class__.__name__
     self.fail_reason = detail
     self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
 except Exception, detail:
     self.status = 'FAIL'
     tb_info = stacktrace.tb_info(sys.exc_info())
     self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
     try:
         self.fail_class = str(detail.__class__.__name__)
         self.fail_reason = str(detail)
     except TypeError:
         self.fail_class = "Exception"
         self.fail_reason = ("Unable to get exception, check the "
                             "traceback for details.")
     for e_line in tb_info:
         self.log.error(e_line)
 finally:
     self.tag_end()
     self.report()
     self.log.info("")
     with open(self.logfile, 'r') as log_file_obj: