diff options
Diffstat (limited to 'xtesting/core/feature.py')
-rw-r--r-- | xtesting/core/feature.py | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/xtesting/core/feature.py b/xtesting/core/feature.py index ed053e09..932e0230 100644 --- a/xtesting/core/feature.py +++ b/xtesting/core/feature.py @@ -27,34 +27,6 @@ class Feature(testcase.TestCase): """Base model for single feature.""" __logger = logging.getLogger(__name__) - dir_results = "/var/lib/xtesting/results" - - def __init__(self, **kwargs): - super(Feature, self).__init__(**kwargs) - self.result_file = "{}/{}.log".format(self.dir_results, self.case_name) - try: - module = kwargs['run']['module'] - self.logger = logging.getLogger(module) - except KeyError: - self.__logger.warning( - "Cannot get module name %s. Using %s as fallback", - kwargs, self.case_name) - self.logger = logging.getLogger(self.case_name) - Feature.configure_logger(self.logger, self.result_file) - - @staticmethod - def configure_logger(logger, result_file): - """Configure the logger to print in result_file.""" - handler = logging.StreamHandler() - handler.setLevel(logging.WARN) - logger.addHandler(handler) - handler = logging.FileHandler(result_file) - handler.setLevel(logging.DEBUG) - logger.addHandler(handler) - formatter = logging.Formatter( - '%(asctime)s - %(name)s - %(levelname)s - %(message)s') - handler.setFormatter(formatter) - logger.addHandler(handler) def execute(self, **kwargs): """Execute the Python method. @@ -104,7 +76,6 @@ class Feature(testcase.TestCase): self.result = 100 except Exception: # pylint: disable=broad-except self.__logger.exception("%s FAILED", self.project_name) - self.__logger.info("Test result is stored in '%s'", self.result_file) self.stop_time = time.time() return exit_code @@ -114,6 +85,11 @@ class BashFeature(Feature): __logger = logging.getLogger(__name__) + def __init__(self, **kwargs): + super(BashFeature, self).__init__(**kwargs) + dir_results = "/var/lib/xtesting/results" + self.result_file = "{}/{}.log".format(dir_results, self.case_name) + def execute(self, **kwargs): """Execute the cmd passed as arg @@ -131,6 +107,8 @@ class BashFeature(Feature): proc = subprocess.Popen(cmd.split(), stdout=f_stdout, stderr=subprocess.STDOUT) ret = proc.wait() + self.__logger.info( + "Test result is stored in '%s'", self.result_file) if ret != 0: self.__logger.error("Execute command: %s failed", cmd) except KeyError: |