def write_step(step, step_color_func, indentation=None): """Write a Step with the given color function""" if indentation is None: indentation_level = 2 if isinstance(step.rule, DefaultRule) else 3 indentation = INDENT_STEP * indentation_level step_text = "{step_keyword} {text}".format(step_keyword=step_color_func( step.used_keyword), text=step_color_func(step.text)) print(indentation + step_text, flush=True) if step.doc_string is not None: doc_string_indentation = indentation + INDENT_STEP print(doc_string_indentation + cf.white('"""'), flush=True) print( cf.deepSkyBlue3( textwrap.indent(step.doc_string, doc_string_indentation)), end="", flush=True, ) print(cf.white(doc_string_indentation + '"""'), flush=True) if step.data_table is not None: data_table_indentation = indentation + INDENT_STEP pretty_table = pretty_print_table(step.data_table, cf.white, cf.deepSkyBlue3) print(textwrap.indent(pretty_table, data_table_indentation), flush=True)
def input_yes_no(sentence): """Generic yes-no question and input catcher""" print(sentence) print(cf.white("Please " + cf.red('press "y" ', nested=True) + "if yes")) print( cf.white("Otherwise, " + cf.green('press any key ', nested=True) + 'to continue')) answer = input(": ") return answer
def console_writer_before_each_feature(self, feature): """ Writes feature header to the console :param Feature feature: the feature to write to the console """ output = "" for tag in feature.tags: output += colorful.cyan(u"@{0}{1}\n".format( tag.name, "({0})".format(tag.arg) if tag.arg else "")) leading = "\n " if feature.description else "" output += u"{0}{1}: {2} # {3}{4}{5}".format( self.get_id_sentence_prefix(feature, colorful.bold_cyan), colorful.bold_white(feature.keyword), colorful.bold_white(feature.sentence), colorful.bold_black(feature.path), leading, colorful.white("\n ".join(feature.description))) if feature.background: output += u"\n\n {0}: {1}".format( colorful.bold_white(feature.background.keyword), colorful.bold_white(feature.background.sentence)) for step in feature.background.all_steps: output += '\n' + self._get_step_before_output( step, colorful.cyan) write(output)
def console_writer_before_each_feature(self, feature): """ Writes feature header to the console :param Feature feature: the feature to write to the console """ output = "" for tag in feature.tags: output += colorful.cyan( "@{0}{1}\n".format(tag.name, "({0})".format(tag.arg) if tag.arg else "") ) leading = "\n " if feature.description else "" output += "{0}{1}: {2} # {3}{4}{5}".format( self.get_id_sentence_prefix(feature, colorful.bold_cyan), colorful.bold_white(feature.keyword), colorful.bold_white(feature.sentence), colorful.bold_black(feature.path), leading, colorful.white("\n ".join(feature.description)), ) if feature.background: output += "\n\n {0}: {1}".format( colorful.bold_white(feature.background.keyword), colorful.bold_white(feature.background.sentence), ) for step in feature.background.all_steps: output += "\n" + self._get_step_before_output(step, colorful.cyan) write(output)
def show(): """ Show the modifiers and colors """ # modifiers sys.stdout.write(colorful.bold('bold') + ' ') sys.stdout.write(colorful.dimmed('dimmed') + ' ') sys.stdout.write(colorful.italic('italic') + ' ') sys.stdout.write(colorful.underlined('underlined') + ' ') sys.stdout.write(colorful.inversed('inversed') + ' ') sys.stdout.write(colorful.concealed('concealed') + ' ') sys.stdout.write(colorful.struckthrough('struckthrough') + '\n') # foreground colors sys.stdout.write(colorful.red('red') + ' ') sys.stdout.write(colorful.green('green') + ' ') sys.stdout.write(colorful.yellow('yellow') + ' ') sys.stdout.write(colorful.blue('blue') + ' ') sys.stdout.write(colorful.magenta('magenta') + ' ') sys.stdout.write(colorful.cyan('cyan') + ' ') sys.stdout.write(colorful.white('white') + '\n') # background colors sys.stdout.write(colorful.on_red('red') + ' ') sys.stdout.write(colorful.on_green('green') + ' ') sys.stdout.write(colorful.on_yellow('yellow') + ' ') sys.stdout.write(colorful.on_blue('blue') + ' ') sys.stdout.write(colorful.on_magenta('magenta') + ' ') sys.stdout.write(colorful.on_cyan('cyan') + ' ') sys.stdout.write(colorful.on_white('white') + '\n')
def display_token(self): if self.token: if self.token.lower() == 'b': return colorful.blue(self.edges.format(self.token)) elif self.token.lower() == 'r': return colorful.red(self.edges.format(self.token)) else: return colorful.white(self.edges.format(' '))
def write_feature_header(feature): """Write the Feature Header to stdout The Feature Header will be printed in the form of: @tag-a @tag-b Feature: short description description line 1 description line 2 """ # write Tags for tag in feature.tags: write_tagline(tag) # write Feature heading feature_heading = "{feature_keyword}: {short_description}".format( feature_keyword=cf.bold_white(feature.keyword), short_description=cf.white(feature.short_description), ) print(feature_heading, flush=True) # write Feature description if available if feature.description: feature_description = "\n".join(INDENT_STEP + l for l in feature.description) print(feature_description + "\n", flush=True) # write Background if available if feature.background: background = "{background_keyword}: {short_description}".format( background_keyword=cf.bold_white(feature.background.keyword), short_description=cf.white(feature.background.short_description) if feature.background.short_description else "", ) print(INDENT_STEP + background, flush=True) # TODO: write background steps for step in feature.background.steps: write_step(step, cf.deepSkyBlue3, indentation=INDENT_STEP + INDENT_STEP) print("", flush=True)
def show(self): print(f"\n \n \n" f"{self.full_product['product_name']} is a better food as it has" f" a nutriscore graded {self.full_product['nutriscore']}." f"\n You can buy it in these stores : " f"{self.full_product['store_name']}" f"\n For more information visit this url : " f"{self.full_product['url']}") print( cf.white("\n If you want to " + cf.red('save', nested=True) + " this food into your favorite, " + cf.red('press "s" ', nested=True) + "\n \n \n"))
def console_writer_before_each_scenario(self, scenario): """ Writes the scenario header to the console :param Scenario scenario: the scenario to write to the console """ output = "\n" if isinstance(scenario.parent, ScenarioOutline): if world.config.write_steps_once: return id_prefix = self.get_id_sentence_prefix( scenario, colorful.bold_yellow, len(scenario.parent.scenarios)) colored_pipe = colorful.bold_white("|") output = " {0}{1} {2} {1}".format( id_prefix, colored_pipe, (" {0} ").format(colored_pipe).join( str( colorful.bold_yellow("{1: <{0}}".format( scenario.parent.get_column_width(i), x))) for i, x in enumerate(scenario.example.data)), ) elif isinstance(scenario.parent, ScenarioLoop): if world.config.write_steps_once: return id_prefix = self.get_id_sentence_prefix( scenario, colorful.bold_yellow, len(scenario.parent.scenarios)) colored_pipe = colorful.bold_white("|") output = " {0}{1} {2: <18} {1}".format( id_prefix, colored_pipe, str(colorful.bold_yellow(scenario.iteration))) else: id_prefix = self.get_id_sentence_prefix(scenario, colorful.bold_cyan) for tag in scenario.tags: if ( tag.name == "precondition" and world.config.expand and world.config.show ): # exceptional for show command when scenario steps expand and tag is a precondition -> comment it out output += colorful.white(" # @{0}{1}\n".format( tag.name, "({0})".format(tag.arg) if tag.arg else "")) else: output += colorful.cyan(" @{0}{1}\n".format( tag.name, "({0})".format(tag.arg) if tag.arg else "")) output += " {0}{1}: {2}".format( id_prefix, colorful.bold_white(scenario.keyword), colorful.bold_white(scenario.sentence), ) write(output)
def write_scenario_header(scenario): """Write the Scenario header""" indentation_level = 1 if isinstance(scenario.rule, DefaultRule) else 2 indentation = INDENT_STEP * indentation_level scenario_heading = "{scenario_keyword}: {short_description}".format( scenario_keyword=cf.bold_white(scenario.keyword), short_description=cf.white(scenario.short_description), ) for tag in scenario.tags: write_tagline(tag, indentation) print(indentation + scenario_heading, flush=True)
def _get_step_before_output(self, step, color_func=None): if color_func is None: color_func = colorful.bold_yellow output = "\r {0}{1}".format( self.get_id_sentence_prefix(step, color_func), color_func(step.sentence) ) if step.text: id_padding = self.get_id_padding(len(step.parent.steps)) output += colorful.bold_white('\n {0}"""'.format(id_padding)) output += colorful.cyan( "".join( [ "\n {0}{1}".format(id_padding, l) for l in step.raw_text ] ) ) output += colorful.bold_white('\n {0}"""'.format(id_padding)) if step.table_header: colored_pipe = colorful.bold_white("|") col_widths = self.get_table_col_widths( [step.table_header] + step.table_data ) # output table header output += "\n {0} {1} {0}".format( colored_pipe, (" {0} ") .format(colored_pipe) .join( str(colorful.white("{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(step.table_header) ), ) # output table data for row in step.table_data: output += "\n {0} {1} {0}".format( colored_pipe, (" {0} ") .format(colored_pipe) .join( str(color_func("{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(row) ), ) return output
def write_rule_header(rule): """Write the Rule header The short description is only written if it's not a DefaultRule """ if isinstance(rule, DefaultRule): return rule_heading = "{rule_keyword}: {short_description}".format( rule_keyword=cf.bold_white(rule.keyword), short_description=cf.white(rule.short_description), ) print(INDENT_STEP + rule_heading + "\n", flush=True)
def _get_step_before_output(self, step, color_func=None): if color_func is None: color_func = colorful.bold_yellow output = "\r {0}{1}".format( self.get_id_sentence_prefix(step, color_func), color_func(step.sentence)) if step.text: id_padding = self.get_id_padding(len(step.parent.steps)) output += colorful.bold_white( '\n {0}"""'.format(id_padding)) output += colorful.cyan("".join([ "\n {0}{1}".format(id_padding, l) for l in step.raw_text ])) output += colorful.bold_white( '\n {0}"""'.format(id_padding)) if step.table_header: colored_pipe = colorful.bold_white("|") col_widths = self.get_table_col_widths([step.table_header] + step.table_data) # output table header output += "\n {0} {1} {0}".format( colored_pipe, (" {0} ").format(colored_pipe).join( str(colorful.white("{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(step.table_header)), ) # output table data for row in step.table_data: output += "\n {0} {1} {0}".format( colored_pipe, (" {0} ").format(colored_pipe).join( str(color_func("{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(row)), ) return output
def show_database(path): """ Show database """ try: db = plyvel.DB(path, create_if_missing=False, paranoid_checks=True) except plyvel.Error as ex: print("Can\'t open DB: {}".format(ex)) return -1 table_data = [TABLE_HEADER] for key, value in db: table_data.append([colorful.white(key), splitstring(repr(value), MAX_VALUE_LEN)]) db.close() table = SingleTable(table_data) table.inner_row_border = True print(table.table) return 0
def console_writer_before_each_scenario(self, scenario): """ Writes the scenario header to the console :param Scenario scenario: the scenario to write to the console """ output = "\n" if isinstance(scenario.parent, ScenarioOutline): if world.config.write_steps_once: return id_prefix = self.get_id_sentence_prefix( scenario, colorful.bold_yellow, len(scenario.parent.scenarios) ) colored_pipe = colorful.bold_white("|") output = " {0}{1} {2} {1}".format( id_prefix, colored_pipe, (" {0} ") .format(colored_pipe) .join( str( colorful.bold_yellow( "{1: <{0}}".format(scenario.parent.get_column_width(i), x) ) ) for i, x in enumerate(scenario.example.data) ), ) elif isinstance(scenario.parent, ScenarioLoop): if world.config.write_steps_once: return id_prefix = self.get_id_sentence_prefix( scenario, colorful.bold_yellow, len(scenario.parent.scenarios) ) colored_pipe = colorful.bold_white("|") output = " {0}{1} {2: <18} {1}".format( id_prefix, colored_pipe, str(colorful.bold_yellow(scenario.iteration)) ) else: id_prefix = self.get_id_sentence_prefix(scenario, colorful.bold_cyan) for tag in scenario.tags: if ( tag.name == "precondition" and world.config.expand and world.config.show ): # exceptional for show command when scenario steps expand and tag is a precondition -> comment it out output += colorful.white( " # @{0}{1}\n".format( tag.name, "({0})".format(tag.arg) if tag.arg else "" ) ) else: output += colorful.cyan( " @{0}{1}\n".format( tag.name, "({0})".format(tag.arg) if tag.arg else "" ) ) output += " {0}{1}: {2}".format( id_prefix, colorful.bold_white(scenario.keyword), colorful.bold_white(scenario.sentence), ) write(output)
def write_usage(self, prog, args="", prefix="Usage: "): return super().write_usage(colorful.white(prog), args=args, prefix=colorful.green(prefix))
def console_writer_after_each_step(self, step): """ Writes the step to the console after it was run :param Step step: the step to write to the console """ if not isinstance(step.parent.parent, Feature): return color_func = self.get_color_func(step.state) line_jump_seq = self.get_line_jump_seq() * ( ((len(step.raw_text) + 3) if step.text else 1) + (len(step.table) + 1 if step.table_header else 0)) output = u'{0} '.format(line_jump_seq) if isinstance(step.parent, ScenarioOutline): # Highlight ScenarioOutline placeholders e.g. '<method>' output += (u''.join( str( colorful.white(item) if ( self._placeholder_regex.search(item) and item.strip('<>') in step.parent.examples_header ) else color_func(item)) for item in self._placeholder_regex.split(step.sentence))) else: output += u"{0}{1}".format( self.get_id_sentence_prefix(step, colorful.bold_cyan), color_func(step.sentence)) if step.text: id_padding = self.get_id_padding(len(step.parent.steps)) output += colorful.bold_white( u'\n {0}"""'.format(id_padding)) output += colorful.cyan(u"".join([ "\n {0}{1}".format(id_padding, l) for l in step.raw_text ])) output += colorful.bold_white( u'\n {0}"""'.format(id_padding)) if step.table_header: colored_pipe = colorful.bold_white("|") col_widths = self.get_table_col_widths([step.table_header] + step.table_data) # output table header output += u"\n {0} {1} {0}".format( colored_pipe, (" {0} ").format(colored_pipe).join( str(colorful.white(u"{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(step.table_header))) # output table data for row in step.table_data: output += u"\n {0} {1} {0}".format( colored_pipe, (" {0} ").format(colored_pipe).join( str(color_func(u"{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(row))) if step.state == step.State.FAILED: if world.config.with_traceback: output += u"\n {0}{1}".format( self.get_id_padding(len(step.parent.steps) - 2), "\n ".join([ str(colorful.red(l)) for l in step.failure.traceback.split("\n")[:-2] ])) output += u"\n {0}{1}: {2}".format( self.get_id_padding(len(step.parent.steps) - 2), colorful.bold_red(step.failure.name), colorful.red(step.failure.reason)) write(output)
def echo(self, message, *args): print( str(colorful.cyan(message)) % tuple(colorful.white(arg) for arg in args))
def console_write(self, features, marker): """ Writes the endreport for all features :param list features: all features """ stats = { "features": {"amount": 0, "passed": 0, "failed": 0, "skipped": 0, "untested": 0, "pending": 0}, "scenarios": {"amount": 0, "passed": 0, "failed": 0, "skipped": 0, "untested": 0, "pending": 0}, "steps": {"amount": 0, "passed": 0, "failed": 0, "skipped": 0, "untested": 0, "pending": 0}, } pending_steps = [] duration = timedelta() for feature in features: if not feature.has_to_run(world.config.scenarios): continue stats["features"]["amount"] += 1 stats["features"][feature.state] += 1 if feature.state in [Step.State.PASSED, Step.State.FAILED]: duration += feature.duration for scenario in feature.all_scenarios: if not scenario.has_to_run(world.config.scenarios): continue if isinstance(scenario, ScenarioOutline): # skip ScenarioOutlines continue if isinstance(scenario, ScenarioLoop): # skip ScenarioLoop continue stats["scenarios"]["amount"] += 1 stats["scenarios"][scenario.state] += 1 for step in scenario.steps: stats["steps"]["amount"] += 1 stats["steps"][step.state] += 1 if step.state == Step.State.PENDING: pending_steps.append(step) colored_closing_paren = colorful.bold_white(")") colored_comma = colorful.bold_white(", ") passed_word = colorful.bold_green("{0} passed") failed_word = colorful.bold_red("{0} failed") skipped_word = colorful.cyan("{0} skipped") pending_word = colorful.bold_yellow("{0} pending") output = colorful.bold_white("{0} features (".format(stats["features"]["amount"])) output += passed_word.format(stats["features"]["passed"]) if stats["features"]["failed"]: output += colored_comma + failed_word.format(stats["features"]["failed"]) if stats["features"]["skipped"]: output += colored_comma + skipped_word.format(stats["features"]["skipped"]) if stats["features"]["pending"]: output += colored_comma + pending_word.format(stats["features"]["pending"]) output += colored_closing_paren output += "\n" output += colorful.bold_white("{} scenarios (".format(stats["scenarios"]["amount"])) output += passed_word.format(stats["scenarios"]["passed"]) if stats["scenarios"]["failed"]: output += colored_comma + failed_word.format(stats["scenarios"]["failed"]) if stats["scenarios"]["skipped"]: output += colored_comma + skipped_word.format(stats["scenarios"]["skipped"]) if stats["scenarios"]["pending"]: output += colored_comma + pending_word.format(stats["scenarios"]["pending"]) output += colored_closing_paren output += "\n" output += colorful.bold_white("{} steps (".format(stats["steps"]["amount"])) output += passed_word.format(stats["steps"]["passed"]) if stats["steps"]["failed"]: output += colored_comma + failed_word.format(stats["steps"]["failed"]) if stats["steps"]["skipped"]: output += colored_comma + skipped_word.format(stats["steps"]["skipped"]) if stats["steps"]["pending"]: output += colored_comma + pending_word.format(stats["steps"]["pending"]) output += colored_closing_paren if pending_steps: sr = StepRegistry() pending_step_implementations = make_unique_obj_list(pending_steps, lambda x: x.definition_func) output += colorful.white("\nYou have {0} pending step implementation{1} affecting {2} step{3}:\n {4}\n\nNote: this could be the reason for some failing subsequent steps".format( len(pending_step_implementations), "s" if len(pending_step_implementations) is not 1 else "", len(pending_steps), "s" if len(pending_steps) is not 1 else "", "\n ".join(["- '{0}' @ {1}".format(sr.get_pattern(s.definition_func), get_func_code(s.definition_func).co_filename) for s in pending_step_implementations]) )) output += "\n" output += colorful.cyan("Run {0} finished within {1}".format(marker, humanize.naturaldelta(duration))) write(output)
def style_text(text): return colorful.white(f'{text}', nested=True)
def inspect_tree(root_path=CURRENT_PATH, options={}, level=ROOT_LEVEL, **kwargs): options = dict(options or {}, **kwargs) indent = options.get('indent', None) silent = options.get('silent', None) if silent != False: silent = bool(silent) or DEFAULT_SILENT if not indent == False: indent = bool(indent) or DEFAULT_INDENT else: indent = 0 output = '' try: if (level == ROOT_LEVEL): root_item_name = color.darkGray(root_path) output += '\n' output += root_item_name items = None try: items = get_tree(root_path, dict(options, **dict(silent=False))) if items is None: raise Error( 'Could not get file system tree object: {0}'.format( root_path)) except Exception as error: raise error prefix = None item_name = None item_output = None item_count = len(items) last_item = items[-1] for item in items: prefix = indent * level * SPACE if item == last_item: prefix += color.darkGray(BRANCH_ITEM_PREFIX_LAST) else: prefix += color.darkGray(BRANCH_ITEM_PREFIX) if item.is_directory: if item.is_link: item_name = SPACE.join([ str(color.bold_white(item.name)), str(color.darkGray(BRANCH_ITEM_LINK_SUFFIX)), str(color.darkGray(item.resolved_relative_path)), str(item.meta), ]) else: item_name = SPACE.join([ str(color.bold_white(item.name)), str(item.meta), ]) elif item.is_file: if item.is_link: item_name = SPACE.join([ str(color.white(item.name)), str(color.darkGray(BRANCH_ITEM_LINK_SUFFIX)), str(color.darkGray(item.resolved_relative_path)), str(item.meta), ]) else: item_name = SPACE.join([ str(color.white(item.name)), str(item.meta), ]) else: if item.is_link: item_name = SPACE.join([ str(color.red(item.name)), str(color.darkGray(BRANCH_ITEM_LINK_SUFFIX)), str(color.darkGray(BRANCH_ITEM_LINK_BROKEN)), str(item.meta), ]) else: item_name = SPACE.join([ str(color.red(item.name)), str(item.meta), ]) output += '\n' output += prefix output += item_name # BUG: unicode issue in Python 2 if item.children: try: item_output = inspect_tree(item.path, options, level + 1) except Exception as error: pass if isinstance(item_output, str): output += item_output if (level == ROOT_LEVEL): output += '\n\n' return output except Exception as error: if not silent: raise error output += '\n\n' output += ' {0}'.format(color.red(str(error).split(' - {')[0])) output += '\n\n' return output
def console_writer_after_each_step(self, step): """ Writes the step to the console after it was run :param Step step: the step to write to the console """ if not isinstance(step.parent.parent, Feature): return color_func = self.get_color_func(step.state) line_jump_seq = self.get_line_jump_seq() * ( ((len(step.raw_text) + 3) if step.text else 1) + (len(step.table) + 1 if step.table_header else 0) ) output = "{0} ".format(line_jump_seq) if isinstance(step.parent, ScenarioOutline): # Highlight ScenarioOutline placeholders e.g. '<method>' output += "".join( str( colorful.white(item) if ( self._placeholder_regex.search(item) and item.strip("<>") in step.parent.examples_header ) else color_func(item) ) for item in self._placeholder_regex.split(step.sentence) ) else: output += "{0}{1}".format( self.get_id_sentence_prefix(step, colorful.bold_cyan), color_func(step.sentence), ) if step.text: id_padding = self.get_id_padding(len(step.parent.steps)) output += colorful.bold_white('\n {0}"""'.format(id_padding)) output += colorful.cyan( "".join( [ "\n {0}{1}".format(id_padding, l) for l in step.raw_text ] ) ) output += colorful.bold_white('\n {0}"""'.format(id_padding)) if step.table_header: colored_pipe = colorful.bold_white("|") col_widths = self.get_table_col_widths( [step.table_header] + step.table_data ) # output table header output += "\n {0} {1} {0}".format( colored_pipe, (" {0} ") .format(colored_pipe) .join( str(colorful.white("{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(step.table_header) ), ) # output table data for row in step.table_data: output += "\n {0} {1} {0}".format( colored_pipe, (" {0} ") .format(colored_pipe) .join( str(color_func("{1: <{0}}".format(col_widths[i], x))) for i, x in enumerate(row) ), ) if step.state == step.State.FAILED: if world.config.with_traceback: output += "\n {0}{1}".format( self.get_id_padding(len(step.parent.steps) - 2), "\n ".join( [ str(colorful.red(l)) for l in step.failure.traceback.split("\n")[:-2] ] ), ) output += "\n {0}{1}: {2}".format( self.get_id_padding(len(step.parent.steps) - 2), colorful.bold_red(step.failure.name), colorful.red(step.failure.reason), ) write(output)
# import termcolor # string = "type-name-function-location" # string = string.replace('-', termcolor.colored('-', 'red')) # print (string) import colorful as cf # create a colored string using clever method translation print(cf.bold_white('Hello World')) # create a colored string using `str.format()` print('{c.bold}{c.lightCoral_on_white}Hello World{c.reset}'.format(c=cf)) # nest colors print(cf.red('red {0} red'.format(cf.white('white')))) print(cf.red('red' + cf.white(' white ', nested=True) + 'red')) # combine styles with strings print(cf.bold & cf.red | 'Hello World') # use true colors cf.use_true_colors() # extend default color palette cf.update_palette({'mint': '#c5e8c8'}) print(cf.mint_on_snow('Wow, this is actually mint')) # choose a predefined style cf.use_style('solarized') # print the official solarized colors
def console_write(self, features, marker): """ Writes the endreport for all features :param list features: all features """ stats = { "features": { "amount": 0, "passed": 0, "failed": 0, "skipped": 0, "untested": 0, "pending": 0, }, "scenarios": { "amount": 0, "passed": 0, "failed": 0, "skipped": 0, "untested": 0, "pending": 0, }, "steps": { "amount": 0, "passed": 0, "failed": 0, "skipped": 0, "untested": 0, "pending": 0, }, } pending_steps = [] duration = timedelta() for feature in features: if not feature.has_to_run(world.config.scenarios): continue stats["features"]["amount"] += 1 stats["features"][feature.state] += 1 if feature.state in [Step.State.PASSED, Step.State.FAILED]: duration += feature.duration for scenario in feature.all_scenarios: if not scenario.has_to_run(world.config.scenarios): continue if isinstance(scenario, ScenarioOutline): # skip ScenarioOutlines continue if isinstance(scenario, ScenarioLoop): # skip ScenarioLoop continue stats["scenarios"]["amount"] += 1 stats["scenarios"][scenario.state] += 1 for step in scenario.steps: stats["steps"]["amount"] += 1 stats["steps"][step.state] += 1 if step.state == Step.State.PENDING: pending_steps.append(step) colored_closing_paren = colorful.bold_white(")") colored_comma = colorful.bold_white(", ") passed_word = colorful.bold_green("{0} passed") failed_word = colorful.bold_red("{0} failed") skipped_word = colorful.cyan("{0} skipped") pending_word = colorful.bold_yellow("{0} pending") output = colorful.bold_white( "{0} features (".format(stats["features"]["amount"]) ) output += passed_word.format(stats["features"]["passed"]) if stats["features"]["failed"]: output += colored_comma + failed_word.format(stats["features"]["failed"]) if stats["features"]["skipped"]: output += colored_comma + skipped_word.format(stats["features"]["skipped"]) if stats["features"]["pending"]: output += colored_comma + pending_word.format(stats["features"]["pending"]) output += colored_closing_paren output += "\n" output += colorful.bold_white( "{} scenarios (".format(stats["scenarios"]["amount"]) ) output += passed_word.format(stats["scenarios"]["passed"]) if stats["scenarios"]["failed"]: output += colored_comma + failed_word.format(stats["scenarios"]["failed"]) if stats["scenarios"]["skipped"]: output += colored_comma + skipped_word.format(stats["scenarios"]["skipped"]) if stats["scenarios"]["pending"]: output += colored_comma + pending_word.format(stats["scenarios"]["pending"]) output += colored_closing_paren output += "\n" output += colorful.bold_white("{} steps (".format(stats["steps"]["amount"])) output += passed_word.format(stats["steps"]["passed"]) if stats["steps"]["failed"]: output += colored_comma + failed_word.format(stats["steps"]["failed"]) if stats["steps"]["skipped"]: output += colored_comma + skipped_word.format(stats["steps"]["skipped"]) if stats["steps"]["pending"]: output += colored_comma + pending_word.format(stats["steps"]["pending"]) output += colored_closing_paren if pending_steps: sr = StepRegistry() pending_step_implementations = make_unique_obj_list( pending_steps, lambda x: x.definition_func ) output += colorful.white( "\nYou have {0} pending step implementation{1} affecting {2} step{3}:\n {4}\n\nNote: this could be the reason for some failing subsequent steps".format( len(pending_step_implementations), "s" if len(pending_step_implementations) is not 1 else "", len(pending_steps), "s" if len(pending_steps) is not 1 else "", "\n ".join( [ "- '{0}' @ {1}".format( sr.get_pattern(s.definition_func), get_func_code(s.definition_func).co_filename, ) for s in pending_step_implementations ] ), ) ) output += "\n" if world.config.wip: if stats["scenarios"]["passed"] > 0: output += colorful.red( "\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:\n" ) has_passed_scenarios = False for feature in features: passed_scenarios = list( filter( lambda s: s.state == Step.State.PASSED, feature.all_scenarios, ) ) for scenario in passed_scenarios: output += colorful.red( "\n - {}: {}".format(feature.path, scenario.sentence) ) has_passed_scenarios = True if has_passed_scenarios: output += "\n" else: output += colorful.green( "\nThe --wip switch was used, so the failures were expected. All is good.\n" ) output += colorful.cyan( "Run {0} finished within {1}".format( marker, humanize.naturaldelta(duration) ) ) write(output)