diff --git a/avocado/core/parameters.py b/avocado/core/parameters.py index ca2f86903662fb98a48c1c195eaa1227fab6bb72..8f6093c90138ecb0c2701ca1c10b13da09ad1e93 100644 --- a/avocado/core/parameters.py +++ b/avocado/core/parameters.py @@ -15,13 +15,12 @@ Module related to test parameters """ +import logging import re from six import iterkeys, iteritems from six.moves import xrange as range -from . import output - class NoMatchError(KeyError): pass @@ -40,18 +39,16 @@ class AvocadoParams(object): You can also iterate through all keys, but this can generate quite a lot of duplicate entries inherited from ancestor nodes. It shouldn't produce false values, though. - - In this version each new "get()" call is logged into avocado.LOG_JOB. - This is subject of change (separate file, perhaps) """ - # TODO: Use "test" to log params.get() - - def __init__(self, leaves, test_id, mux_path): + def __init__(self, leaves, test_id, mux_path, logger_name=None): """ :param leaves: List of TreeNode leaves defining current variant :param test_id: test id :param mux_path: list of entry points + :param logger_name: the name of a logger to use to record attempts + to get parameters + :type logger_name: str """ self._rel_paths = [] leaves = list(leaves) @@ -64,6 +61,7 @@ class AvocadoParams(object): self._abs_path = AvocadoParam(path_leaves, '*: *') self.id = test_id self._cache = {} # TODO: Implement something more efficient + self._logger_name = logger_name def __eq__(self, other): if set(iterkeys(self.__dict__)) != set(iterkeys(other.__dict__)): @@ -76,15 +74,6 @@ class AvocadoParams(object): def __ne__(self, other): return not (self == other) - def __getstate__(self): - """ log can't be pickled """ - copy = self.__dict__.copy() - return copy - - def __setstate__(self, orig): - """ refresh log """ - self.__dict__.update(orig) - def __repr__(self): return "" % self._str() @@ -98,11 +87,6 @@ class AvocadoParams(object): else: return self._abs_path.str_leaves_variant - def log(self, key, path, default, value): - """ Predefined format for displaying params query """ - output.LOG_JOB.debug("PARAMS (key=%s, path=%s, default=%s) => %r", key, - path, default, value) - def _get_matching_leaves(self, path, leaves): """ Pops and returns list of matching nodes @@ -160,7 +144,10 @@ class AvocadoParams(object): # KeyError - first query # TypeError - unable to hash value = self._get(key, path, default) - self.log(key, path, default, value) + if self._logger_name is not None: + logger = logging.getLogger(self._logger_name) + logger.debug("PARAMS (key=%s, path=%s, default=%s) => %r", + key, path, default, value) try: self._cache[(key, path, default)] = value except TypeError: diff --git a/avocado/core/test.py b/avocado/core/test.py index 0251ce88165d57a88e26bd778756657704171e82..4b0fd31fd52e5ece11fe6e9bfadc5a5cab05ed3f 100644 --- a/avocado/core/test.py +++ b/avocado/core/test.py @@ -367,7 +367,7 @@ class Test(unittest.TestCase, TestData): elif isinstance(params, tuple): params, mux_path = params[0], params[1] self.__params = parameters.AvocadoParams(params, self.name, - mux_path) + mux_path, self.__log.name) default_timeout = getattr(self, "timeout", None) self.timeout = self.params.get("timeout", default=default_timeout) diff --git a/optional_plugins/loader_yaml/avocado_loader_yaml/__init__.py b/optional_plugins/loader_yaml/avocado_loader_yaml/__init__.py index 52f8ea3cd38f8d38ccbbaaa38b8567c381a9480b..ea6308bc9f77efd33bc7546c15ca0745a3242306 100644 --- a/optional_plugins/loader_yaml/avocado_loader_yaml/__init__.py +++ b/optional_plugins/loader_yaml/avocado_loader_yaml/__init__.py @@ -19,6 +19,7 @@ from six import iteritems from avocado.core import loader from avocado.core import parameters +from avocado.core import output from avocado.core.plugin_interfaces import CLI from avocado_varianter_yaml_to_mux import create_from_yaml from avocado_varianter_yaml_to_mux import mux @@ -101,7 +102,7 @@ class YamlTestsuiteLoader(loader.TestLoader): mux_tree = mux.MuxTree(root) for variant in mux_tree: params = parameters.AvocadoParams(variant, "YamlTestsuiteLoader", - ["/run/*"]) + ["/run/*"], output.LOG_UI.name) reference = params.get("test_reference") test_loader = self._get_loader(params) if not test_loader: