Beispiel #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)
Beispiel #2
0
 def test_filelock(self):
     players = 1000
     pool = multiprocessing.Pool(players)
     args = [(self.tmpdir, players)] * players
     try:
         pool.map(file_lock_action, args)
     except:
         msg = 'Failed to run FileLock with %s players:\n%s'
         msg %= (players, prepare_exc_info(sys.exc_info()))
         self.fail(msg)
Beispiel #3
0
 def test_filelock(self):
     players = 1000
     pool = multiprocessing.Pool(players)
     args = [(self.tmpdir, players)] * players
     try:
         pool.map(file_lock_action, args)
     except:
         msg = 'Failed to run FileLock with %s players:\n%s'
         msg %= (players, prepare_exc_info(sys.exc_info()))
         self.fail(msg)
Beispiel #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()
Beispiel #5
0
    def run_avocado(self, result=None):
        """
        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(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())
Beispiel #6
0
    def run_avocado(self, result=None):
        """
        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(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())
Beispiel #7
0
 def test_filelock(self):
     # Calculate the timeout based on t_100_iter + 2e-5*players
     start = time.time()
     for _ in range(100):
         with FileLock(self.tmpdir):
             pass
     timeout = 0.02 + (time.time() - start)
     players = 1000
     pool = multiprocessing.Pool(players)
     args = [(self.tmpdir, players, timeout)] * players
     try:
         pool.map(file_lock_action, args)
     except:
         msg = 'Failed to run FileLock with %s players:\n%s'
         msg %= (players, prepare_exc_info(sys.exc_info()))
         self.fail(msg)
Beispiel #8
0
 def test_filelock(self):
     # Calculate the timeout based on t_100_iter + 2e-5*players
     start = time.time()
     for _ in range(100):
         with FileLock(self.tmpdir.name):
             pass
     timeout = 0.02 + (time.time() - start)
     players = 1000
     pool = multiprocessing.Pool(players)
     args = [(self.tmpdir.name, players, timeout)] * players
     try:
         pool.map(file_lock_action, args)
     except Exception:
         msg = 'Failed to run FileLock with %s players:\n%s'
         msg %= (players, prepare_exc_info(sys.exc_info()))
         self.fail(msg)
Beispiel #9
0
def load_test(test_factory):
    """
    Load test from the test factory.

    :param test_factory: a pair of test class and parameters.
    :type test_factory: tuple
    :return: an instance of :class:`avocado.core.test.Test`.
    """
    test_class, test_parameters = test_factory
    if 'modulePath' in test_parameters:
        test_path = test_parameters.pop('modulePath')
    else:
        test_path = None
    if isinstance(test_class, str):
        module_name = os.path.basename(test_path).split('.')[0]
        test_module_dir = os.path.abspath(os.path.dirname(test_path))
        # Tests with local dir imports need this
        try:
            sys.path.insert(0, test_module_dir)
            f, p, d = imp.find_module(module_name, [test_module_dir])
            test_module = imp.load_module(module_name, f, p, d)
        except:  # pylint: disable=W0702
            # On load_module exception we fake the test class and pass
            # the exc_info as parameter to be logged.
            test_parameters['methodName'] = 'test'
            exception = stacktrace.prepare_exc_info(sys.exc_info())
            test_parameters['exception'] = exception
            return TestError(**test_parameters)
        finally:
            if test_module_dir in sys.path:
                sys.path.remove(test_module_dir)
        for _, obj in inspect.getmembers(test_module):
            if (inspect.isclass(obj) and obj.__name__ == test_class and
                    inspect.getmodule(obj) == test_module):
                if issubclass(obj, test.Test):
                    test_class = obj
                    break
    if test_class is test.DryRunTest:
        test_parameters['modulePath'] = test_path
    if 'run.results_dir' in test_parameters:
        test_parameters['base_logdir'] = test_parameters.pop('run.results_dir')
    test_instance = test_class(**test_parameters)

    return test_instance
Beispiel #10
0
 :result: Unused param, compatibility with :class:`unittest.TestCase`.
 """
 self._setup_environment_variables()
 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()
Beispiel #11
0
 :result: Unused param, compatibility with :class:`unittest.TestCase`.
 """
 self._setup_environment_variables()
 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()