def lock(cls, config=None, skip_init=False, **kwargs): """Lock an instance of this resource class. Args: config (str): path to the json config file. skip_init (bool): whether to skip initialization or not. kwargs (dict): additional query parameters for the request, e.g. name or group. Returns: BaseResource. locked and initialized resource, ready for work. """ # These runtime imports are done to avoid cyclic imports. from rotest.core.runner import parse_config_file from rotest.management.client.manager import (ClientResourceManager, ResourceRequest) if BaseResource._SHELL_CLIENT is None: BaseResource._SHELL_CLIENT = ClientResourceManager() resource_request = ResourceRequest(BaseResource._SHELL_REQUEST_NAME, cls, **kwargs) config_dict = None if config is not None: config_dict = parse_config_file(config) result = BaseResource._SHELL_CLIENT.request_resources( [resource_request], config=config_dict, skip_init=skip_init, use_previous=False) return result[BaseResource._SHELL_REQUEST_NAME]
def main(*tests): """Run the given tests. Args: *tests: either suites or tests to be run. """ django.setup() parser = create_client_options_parser() arguments = parser.parse_args() config = AttrDict( chain( parse_config_file(DEFAULT_CONFIG_PATH).items(), parse_config_file(arguments.config_path).items(), filter_valid_values(vars(arguments)), )) # In case we're called via 'python test.py ...' if not sys.argv[0].endswith("rotest"): main_module = inspect.getfile(__import__("__main__")) config.paths = (main_module, ) if len(tests) == 0: tests = discover_tests_under_paths(config.paths) if config.filter is not None: tests = [ test for test in tests if match_tags(get_tags_by_class(test), config.filter) ] for entry_point in \ pkg_resources.iter_entry_points("rotest.cli_client_actions"): core_log.debug("Applying entry point %s", entry_point.name) extension_action = entry_point.load() extension_action(tests, config) if len(tests) == 0: print("No test was found") sys.exit(1) class AlmightySuite(TestSuite): components = tests run_tests(test=AlmightySuite, config=config)
def pytest_sessionstart(session): """Read and initialize Rotest global fields.""" config = session.config RotestRunContext.CONFIG = AttrDict( chain( six.iteritems(parse_config_file(DEFAULT_CONFIG_PATH)), six.iteritems(parse_config_file(config.option.config_path)), filter_valid_values({ 'outputs': config.option.outputs, 'debug': config.option.ipdbugger }))) if not session.config.option.collectonly: RotestRunContext.RUN_DATA = RunData( config=json.dumps(RotestRunContext.CONFIG)) RotestRunContext.RESOURCE_MANAGER = ClientResourceManager( logger=core_log) class AlmightySuite(TestSuite): components = [TestCase] main_test = AlmightySuite( run_data=RotestRunContext.RUN_DATA, config=config, indexer=RotestRunContext.INDEXER, skip_init=RotestRunContext.CONFIG.skip_init, save_state=RotestRunContext.CONFIG.save_state, enable_debug=RotestRunContext.CONFIG.debug, resource_manager=RotestRunContext.RESOURCE_MANAGER) RotestRunContext.MAIN_TEST = main_test main_test._tests = [] main_test.name = main_test.get_name() main_test.data = SuiteData(name=main_test.name, run_data=RotestRunContext.RUN_DATA) if not session.config.option.collectonly: RotestRunContext.RUN_DATA.main_test = main_test.data RotestRunContext.RESULT = Result( stream=sys.stdout, outputs=RotestRunContext.CONFIG.outputs, main_test=main_test)
from attrdict import AttrDict from rotest.core.result.result import Result from rotest.management.base_resource import BaseResource from rotest.management.client.manager import ClientResourceManager from rotest.common.config import SHELL_APPS, SHELL_STARTUP_COMMANDS from rotest.core.runner import parse_config_file, DEFAULT_CONFIG_PATH from rotest.core.result.handlers.stream.log_handler import LogDebugHandler # Mock tests result object for running blocks blocks_result = Result(stream=None, descriptions=None, outputs=[], main_test=None) # Mock tests configuration for running blocks blocks_config = AttrDict(parse_config_file(DEFAULT_CONFIG_PATH)) # Container for data shared between blocks shared_data = {} ENABLE_DEBUG = False IMPORT_BLOCK_UTILS = \ "from rotest.management.utils.shell import shared_data, run_block" IMPORT_RESOURCE_LOADER = \ "from rotest.management.utils.resources_discoverer import get_resources" class ShellMockFlow(object): """Mock class used for sharing data between blocks.""" parents_count = 0
def main(*tests): """Run the given tests. Args: *tests: either suites or tests to be run. """ # Load django models before using the runner in tests. django.setup() if sys.argv[0].endswith("rotest"): argv = sys.argv[1:] else: argv = sys.argv version = pkg_resources.get_distribution("rotest").version arguments = docopt.docopt(__doc__, argv=argv, version=version) arguments = dict(paths=arguments["<path>"] or ["."], config_path=arguments["--config"] or DEFAULT_CONFIG_PATH, save_state=arguments["--save-state"], delta_iterations=int(arguments["--delta"]) if arguments["--delta"] is not None else None, processes=int(arguments["--processes"]) if arguments["--processes"] is not None else None, outputs=parse_outputs_option(arguments["--outputs"]), filter=arguments["--filter"], run_name=arguments["--name"], list=arguments["--list"], fail_fast=arguments["--failfast"], debug=arguments["--debug"], skip_init=arguments["--skip-init"], resources=arguments["--resources"]) config = parse_config_file(arguments["config_path"]) default_config = parse_config_file(DEFAULT_CONFIG_PATH) options = AttrDict( chain( default_config.items(), filter_valid_values(config), filter_valid_values(arguments), )) if not sys.argv[0].endswith("rotest") and len(tests) == 0: main_module = inspect.getfile(__import__("__main__")) options.paths = (main_module, ) if len(tests) == 0: tests = discover_tests_under_paths(options.paths) if len(tests) == 0: print("No test was found at given paths: {}".format(", ".join( options.paths))) sys.exit(1) class AlmightySuite(TestSuite): components = tests run_tests(test=AlmightySuite, save_state=options.save_state, delta_iterations=options.delta_iterations, processes=options.processes, outputs=set(options.outputs), filter=options.filter, run_name=options.run_name, list=options.list, fail_fast=options.fail_fast, debug=options.debug, skip_init=options.skip_init, config_path=options.config_path, resources=options.resources)