avocado.core.utils package
Submodules
avocado.core.utils.eggenv module
- avocado.core.utils.eggenv.get_python_path_env_if_egg()
Returns an environment mapping with an extra PYTHONPATH for the egg or None
When running Avocado Python modules, the interpreter on the new process needs to know where Avocado can be found. This is usually handled by the Avocado installation being available to the standard Python installation, but if Avocado is running from an uninstalled egg, it needs extra help.
- Returns:
environment mapping with an extra PYTHONPATH for the egg or None
- Return type:
os.environ mapping or None
avocado.core.utils.entry_points module
Compatibility helpers for importlib.metadata.entry_points.
The entry_points() API changed across Python versions:
Python 3.8/3.9 - returns a plain dict; group= kwarg not supported Python 3.10/3.11 - returns SelectableGroups; group= kwarg supported Python 3.12+ - returns EntryPoints; group= kwarg supported; no .get()/.groups
These helpers provide a single version-agnostic API for the whole codebase.
- avocado.core.utils.entry_points.get_entry_point_groups()
Return all registered entry point group names, compatible with Python 3.8+.
- Returns:
list of group name strings
- Return type:
- avocado.core.utils.entry_points.get_entry_point_module_name(entry_point)
Return the module name declared by an entry point.
- avocado.core.utils.entry_points.get_entry_points_for(group)
Return entry points belonging to group, compatible with Python 3.8+.
On Python 3.9 (el9),
importlib.metadata.entry_points()is called with no arguments and returns a plain dict. In RPM build environments the same package version can appear in more than onedist-infodirectory onsys.path(e.g. both the system install and the BUILDROOT install), which causes the same entry point to be listed multiple times in that dict. The deduplication below guards against loading a plugin class more than once, which would otherwise cause every plugin method to be invoked twice per event (leading to errors likeFileExistsErrorin the bystatus plugin).- Parameters:
group (str) – entry point group name (e.g.
"avocado.plugins.cli")- Returns:
sequence of entry points in the requested group, deduplicated
avocado.core.utils.loader module
- avocado.core.utils.loader.load_test(test_factory)
Load test from the test factory.
- Parameters:
test_factory (tuple) – a pair of test class and parameters.
- Returns:
an instance of
avocado.core.test.Test.
avocado.core.utils.messages module
- class avocado.core.utils.messages.FileMessage
Bases:
GenericRunningMessageCreates file message with all necessary information.
- classmethod get(msg, path)
Creates running message with all necessary information.
- message_type = 'file'
- class avocado.core.utils.messages.FinishedMessage
Bases:
GenericMessage- classmethod get(result, fail_reason=None, returncode=None, class_name=None, fail_class=None, traceback=None, **kwargs)
Creates finished message with all necessary information.
- Parameters:
result (values for the statuses defined in :class: avocado.core.teststatus.STATUSES) – test result
fail_reason (str) – parameter for brief specification, of the failed result.
returncode – exit status of runner
class_name (str) – class name of the test
fail_class (str) – Exception class of the failure
traceback (str) – Traceback of the exception
- Returns:
finished message
- Return type:
- message_status = 'finished'
- class avocado.core.utils.messages.GenericMessage
Bases:
object- classmethod get(**kwargs)
Creates message base on it’s type with all necessary information.
- Returns:
message dict which can be send to avocado server
- Return type:
- message_status = None
- class avocado.core.utils.messages.GenericRunningMessage
Bases:
GenericMessage- classmethod get(msg, **kwargs)
Creates running message with all necessary information.
- message_status = 'running'
- message_type = None
- class avocado.core.utils.messages.LogMessage
Bases:
GenericRunningMessage- message_type = 'log'
- class avocado.core.utils.messages.OutputMessage
Bases:
GenericRunningMessageCreates output message with all necessary information.
- message_type = 'output'
- class avocado.core.utils.messages.RunnerLogHandler(queue, message_type, kwargs=None)
Bases:
HandlerRunner logger which will put every log to the runner queue
- Parameters:
queue (multiprocessing.SimpleQueue) – queue for the runner messages
message_type (string) – type of the log
- emit(record)
Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
- property message_only_formatter
Property that initiates a
logging.Formatterlazily
- class avocado.core.utils.messages.RunningMessage
Bases:
GenericMessageCreates running message without any additional info.
- message_status = 'running'
- class avocado.core.utils.messages.StartedMessage
Bases:
GenericMessage- message_status = 'started'
- class avocado.core.utils.messages.StderrMessage
Bases:
GenericRunningMessageCreates stderr message with all necessary information.
- message_type = 'stderr'
- class avocado.core.utils.messages.StdoutMessage
Bases:
GenericRunningMessageCreates stdout message with all necessary information.
- message_type = 'stdout'
- class avocado.core.utils.messages.StreamToQueue(queue, message_type)
Bases:
objectRunner Stream which will transfer data to the runner queue
- Parameters:
queue (multiprocessing.SimpleQueue) – queue for the runner messages
message_type (string) – type of the log
- flush()
- write(buf)
- class avocado.core.utils.messages.WhiteboardMessage
Bases:
GenericRunningMessageCreates whiteboard message with all necessary information.
- message_type = 'whiteboard'
- avocado.core.utils.messages.start_logging(config, queue)
Helper method for connecting the avocado logging with avocado messages.
It will add the logHandlers to the :class: avocado.core.output loggers, which will convert the logs to the avocado messages and sent them to processing queue.
- Parameters:
config (dict) – avocado configuration
queue (multiprocessing.SimpleQueue) – queue for the runner messages
avocado.core.utils.path module
- avocado.core.utils.path.prepend_base_path(value)
- avocado.core.utils.path.system_wide_or_base_path(file_path)
Returns either a system wide path, or one relative to the base.
This utility function is helpful when locating configuration files and takes into account system specific conditions, such as whether configuration will normally be under “/etc” or “/usr/local/etc”.
If “etc/avocado/avocado.conf” is given as input, it checks for the existence of “/etc/avocado/avocado.conf”. If that path does not exist, then a path starting with the avocado’s Python’s distribution is returned. In that case it’d return something like “/usr/lib/python3.9/site-packages/avocado/etc/avocado/avocado.conf”.
- Parameters:
file_path (str) – a filesystem path that can either be absolute, or relative. If relative, the absolute equivalent (that is, by prefixing the filesystem root location) is checked for existence. If it does not exist, a path relative to the Python’s distribution base path is returned.
- Return type:
avocado.core.utils.version module
- avocado.core.utils.version.get_avocado_git_version()