Example #1
0
 def test_simple_write(self):
     with patch('click.echo', self.mock_print):
         output.write('text is printed')
         is_correct = self.mock_print.mock_calls[-1] == call(
             'text is printed')
         assert is_correct, 'Printed text is not correct, found: "{}"'.format(
             self.mock_print.mock_calls[-1])
Example #2
0
 def test_indent_increased(self):
     with patch('click.echo', self.mock_print):
         output.inc_indent()
         output.write('text is printed')
         is_correct = self.mock_print.mock_calls[-1] == call(
             '   text is printed')
         assert is_correct, 'Printed text is not correct, found: "{}", {}'.format(
             self.mock_print.mock_calls[-1], call('   text is printed'))
Example #3
0
def print_stats(stats):
    output.br()
    scenario = output.get_success(
        stats.get('scenario')) if stats.get('status') else output.get_error(
            stats.get('scenario'))
    output.write('Scenario: "%s" total_time: %s' %
                 (scenario, stats['elapsed']))
    output.br()

    table_rows = [
        get_step_stats_row(step_stats)
        for step_stats in stats.get('steps_stats')
    ]
    table = tabulate(table_rows,
                     headers=[
                         '%s#' % output.get_indent(), 'Step', 'Status',
                         'Elapsed time'
                     ])

    output.write_raw(table)

    output.br()
Example #4
0
 def after_each(self):
     output.reset_indent()
     output.write(output.c(':: after each', 'cyan'))
     [f() for f in self.hooks['after_each']]
     return
Example #5
0
 def before_each(self):
     output.reset_indent()
     output.write(output.c(':: before each', 'cyan'))
     [f() for f in self.hooks['before_each']]
     return
Example #6
0
def collect_steps(runner):
    for (expression, f) in steps:
        output.write('* adding step definition: {} \
                     '.format(expression))
        runner.add_step_definition(expression, f)
Example #7
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)