示例#1
0
def test_class_decorator_collect_tests(with_dec_classpath, tmpdir):
    from tiden.result import Result

    var_dir = str(tmpdir.mkdir('var'))
    suite_var_dir = str(tmpdir.join('var').mkdir('suite-mock'))
    xunit_file = str(tmpdir.join('var').join('xunit.xml'))
    tmpdir.join('var').join('xunit.xml').write('', ensure=True)
    report_path = 'report.yaml'

    res = Result(xunit_path=xunit_file)
    config = {
        'artifacts': {},
        'suite_var_dir': suite_var_dir,
        'suite_name': 'mock',
        'test_name': '*',
        'suite_dir': join(dirname(__file__), 'res', 'decorators', 'suites'),
        'remote': {
            'suite_var_dir': '',
        }
    }
    modules = {
        'mock.mock_test_module': {
            'path': '%s/mock/mock_test_module.py' % config['suite_dir'],
            'module_short_name': 'mock_test_module',
        },
        'mock.mock_test_module_with_test_configuration': {
            'path':
            '%s/mock/mock_test_module_with_test_configuration.py' %
            config['suite_dir'],
            'module_short_name':
            'mock_test_module_with_test_configuration',
        },
        'mock.mock_test_module_with_test_configuration_subset': {
            'path':
            '%s/mock/mock_test_module_with_test_configuration_subset.py' %
            config['suite_dir'],
            'module_short_name':
            'mock_test_module_with_test_configuration_subset',
        },
    }
    from tiden.tidenrunner import TidenRunner
    tr = TidenRunner(config,
                     modules=modules,
                     xunit_path=xunit_file,
                     collect_only=True)
    tr.collect_tests()
    res = tr.get_tests_results()
    res.flush_xunit()
    res.create_testrail_report(config, report_file=str(report_path))
示例#2
0
def main():
    """
    Run Tiden tests
    """
    log_print("*** Initialization ***", color='blue')
    log_print('(c) 2017-{} GridGain Systems. All Rights Reserved'.format(
        max(datetime.now().year, 2019)))
    log_print(version)
    exit_code = None

    # parse arguments,
    # load configuration,
    # initialize working directories
    config = TidenFabric().setConfig(setup_test_environment(
        process_args())).obj
    log_print('The configuration stored in %s' % config['config_path'])

    logger = _get_default_logger(config)
    sys.path.insert(0, abspath(getcwd()))

    pm = PluginManager(config)

    # prepare artifacts, artifact information is updated into config
    # this must be done before tests collections,
    # because some tests are applicable for specific artifacts only
    log_print('*** Prepare artifacts ***', color='blue')
    pm.do('before_prepare_artifacts', config)
    remote_unzip_files, config = prepare(config)

    if collect_only:
        # we don't run any test, so no ssh pool nor plugin manager required
        ssh_pool = None
        pm = None
    else:
        # otherwise, create ssh pool,
        # and prepare plugins to use it
        ssh_pool = init_ssh_pool(config)
        if pm.plugins:
            log_print('*** Plugins ***', color='blue')
            for name, plugin in pm.plugins.items():
                log_print("%s, version %s" %
                          (name, plugin['TIDEN_PLUGIN_VERSION']))
            pm.set(ssh=ssh_pool)

    # initialize tests runner
    log_print('*** Runner ***', color='blue')
    tr = TidenRunner(config,
                     collect_only=collect_only,
                     ssh_pool=ssh_pool,
                     plugin_manager=pm)
    if len(tr.modules.keys()) == 0:
        log_print("Error: no test modules found")
        exit(1)
    log_print(
        "%s module(s) matched %s.%s" %
        (len(tr.modules.keys()), config['suite_name'], config['test_name']))

    if collect_only:
        tr.collect_tests()
    else:
        pm.do('before_hosts_setup')
        init_remote_hosts(ssh_pool, config)

        pm.do('after_hosts_setup')
        upload_artifacts(ssh_pool, config, remote_unzip_files)

        if pm.do_check('before_tests_run'):
            tr.process_tests()
        else:
            exit_code = -1
        pm.do('after_tests_run')

    result = tr.get_tests_results()
    result.flush_xunit()
    result.print_summary()
    result.create_testrail_report(config,
                                  report_file=config.get('testrail_report'))

    print_blue("Execution time %d:%02d:%02d " %
               hms(int(time()) - result.get_started()))

    if exit_code:
        exit(exit_code)
示例#3
0
def test_runner_collect(with_dec_classpath, local_config, tmpdir, mock_pm):
    var_dir = _ensure_var_dir(tmpdir)
    xunit_file_collect = _ensure_xunit_file_empty(var_dir, '-collect')
    xunit_file_process = _ensure_xunit_file_empty(var_dir, '-process')
    testrail_report_file_collect = _ensure_tr_report_file_empty(var_dir, '-collect')
    testrail_report_file_process = _ensure_tr_report_file_empty(var_dir, '-process')

    suite_var_dir = str(var_dir.mkdir('suite-mock'))
    config_path = str(var_dir.join('config.yaml'))

    source = 'mock_test_module_with_test_configuration'
    suite = 'mock'
    module_name = 'suites.%s.%s.MockTestModuleWithTestConfiguration' % (suite, source)
    test_prefix = module_name + '.'

    config = deepcopy(local_config)

    config.update({
        'artifacts': {},
        'suite_var_dir': suite_var_dir,
        'suite_dir': join(dirname(__file__), 'res', 'decorators', 'suites'),
        'remote': {
            'suite_var_dir': suite_var_dir,
        },
        'config_path': config_path,
        'zookeeper_enabled': False,
        'pitr_enabled': False,
        'compaction_enabled': True,
    })

    ssh_pool = LocalPool(local_config['ssh'])
    test_module_source_file_name = '%s/%s/%s.py' % (config['suite_dir'], suite, source)

    modules = {
        '%s.%s' % (suite, source): {
            'path': test_module_source_file_name,
            'module_short_name': source,
        }
    }
    test_configuration = '(pitr_enabled=false, compaction_enabled=true, zookeeper_enabled=false)'
    expected_configuration_options = ['pitr_enabled', 'compaction_enabled', 'zookeeper_enabled']
    expected_result = {
        'test_main':
            {'status': 'pass', 'type': None, 'message': None},
        'test_zookeeper_only':
            {'status': 'skipped', 'type': 'skipped cause of config.zookeeper_enabled is None', 'message': None},
    }

    from tiden.tidenfabric import TidenFabric
    TidenFabric().reset().setConfig(config)

    tr = TidenRunner(config, modules=modules, ssh_pool=ssh_pool, plugin_manager=mock_pm, xunit_path=xunit_file_collect)
    tr.collect_tests()
    res = tr.get_tests_results()
    res.update_xunit()
    res.create_testrail_report(config, report_file=basename(testrail_report_file_collect))
    _tests = res.get_tests()
    assert 12 == len(_tests)
    print(_tests)

    TidenFabric().reset().setConfig(config)
    tr = TidenRunner(config, modules=modules, ssh_pool=ssh_pool, plugin_manager=mock_pm, xunit_path=xunit_file_process)
    tr.process_tests()
    res = tr.get_tests_results()
    res.create_testrail_report(config, report_file=basename(testrail_report_file_process))
    _tests = res.get_tests()
    assert 2 == len(_tests)
    print(_tests)
示例#4
0
def test_runner_empty():
    tr = TidenRunner({}, ssh_pool=None, modules={})
    assert 0 == tr.long_path_len
    tr.collect_tests()