#! /usr/bin/python3 # SPDX-License-Identifier: GPL-2.0-or-later # # Copyright Red Hat # Author: David Gibson """ Manage the manifest of classless tests in a module """ import sys MANIFEST = "__avocado_classless__" def manifest(mod): """Return avocado-classless manifest for a Python module""" if not hasattr(mod, MANIFEST): setattr(mod, MANIFEST, {}) return getattr(mod, MANIFEST) class ManifestTestInfo: # pylint: disable=R0903 """Metadata about a classless test""" def __init__(self, func): self.func = func def run_test(self): self.func() def manifest_add(mod, name, func): """Register a function as a classless test""" if isinstance(mod, str): mod = sys.modules[mod] mfest = manifest(mod) if name in mfest: raise ValueError(f"Duplicate classless test name {name}") mfest[name] = ManifestTestInfo(func)