diff options
author | Panagiotis Karalis <pkaralis@intracom-telecom.com> | 2018-05-25 12:27:12 +0300 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-05-30 09:12:06 +0200 |
commit | f990bd3c8cbac17d4c0d36b18e5debb58a72402c (patch) | |
tree | 9a402c16176e14cfa8d0c86834e54f0ed35586ab /xtesting/core/feature.py | |
parent | bc5536857fba214409fb02bc4e0f2f0ebb4c7b9c (diff) |
Remove Feature logger
This class atttribute is removed as it's quite useless (it forces one
module per project). All messages are now printed to xtesting.log
whatever the namespace and all warnings are printed in console.
Co-Authored-By: Cédric Ollivier <cedric.ollivier@orange.com>
Change-Id: I6860eaf427093ea21b3bd78650bec7939e947b2d
Signed-off-by: Panagiotis Karalis <pkaralis@intracom-telecom.com>
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 0249623ab94035ca0ea363d9a86847c2e7a5ee93)
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: |