예제 #1
0
 def setUp(self):
     self.mock_print = Mock()
     output.reset_indent()
예제 #2
0
 def before_each(self):
     output.reset_indent()
     output.write(output.c(':: before each', 'cyan'))
     [f() for f in self.hooks['before_each']]
     return
예제 #3
0
 def after_each(self):
     output.reset_indent()
     output.write(output.c(':: after each', 'cyan'))
     [f() for f in self.hooks['after_each']]
     return
예제 #4
0
def spin(tags, features_path, root_path, fail_fast, show_stats, verbose):
    output.write(
        get_title(root_path, features_path, fail_fast, show_stats, verbose))
    if not os.path.isabs(features_path):
        features_path = os.path.realpath(features_path)
    # Appending features to the sys.path
    sys.path.append(features_path)
    if not os.path.isabs(root_path):
        root_path = os.path.realpath(root_path)
    # Appending steps to the sys.path
    sys.path.append(root_path)

    all_tags = [] if tags == '' else tags.split(' ')

    output.br()
    config.fail_fast = fail_fast
    config.verbose = verbose
    collect_steps(runner)

    feature_files = glob.glob('{}/*.feature'.format(features_path))
    output.br()
    for feature_file in feature_files:
        output.write('* collecting feature: {}'.format(feature_file))
        features.parse_file(feature_file)

    should_run_all = len(all_tags) == 0

    def has_at_least_one_tag(scenario_tags):
        total_found_tags = len(
            [tag for tag in all_tags if tag in scenario_tags])
        return total_found_tags > 0

    output.br()
    output.write('* running scenarios')
    output.br()
    run_context(config.before_all, config.after_all)

    has_failed = False
    for scenario in features.scenarios:
        if should_run_all or has_at_least_one_tag(scenario.tags):
            output.br()
            if run_context(config.before_each,
                           config.after_each,
                           skip_exit=True):
                output.reset_indent()
                output.br()
                output.write('{}: {}'.format(output.c('Scenario', 'white'),
                                             output.c(scenario.name, 'cyan')))
                output.inc_indent()
                stats = runner.run_scenario(scenario)
                if not has_failed and not stats['status']:
                    has_failed = True

                if show_stats:
                    output.br()
                    print_stats(stats)

                output.br()
                run_context(config.after_each,
                            lambda: output.warn(
                                'after_each failed, exit will be skipped'),
                            skip_exit=True)

                if fail_fast and has_failed:
                    # If scenario failed and it is fast fail
                    # we only want to leave the loop
                    break

    output.br()
    config.after_all()
    sys.exit(1 if has_failed else 0)