How to use _print_test_stage method in tavern

Best Python code snippet using tavern

error.py

Source:error.py Github

copy

Full Screen

...77 red = False78 line = " {} = '{}'".format(var[1:-1], value_at_call)79 tw.line(line, white=white, red=red) # pragma: no cover80 return missing81 def _print_test_stage(82 self, tw, code_lines, missing_format_vars, line_start83 ): # pylint: disable=no-self-use84 """Print the direct source lines from this test stage85 If we couldn't get the stage for some reason, print the entire test out.86 If there are any lines which have missing format variables, higlight87 them in red.88 Args:89 tw (Termin): Pytest TW instance90 code_lines (list(str)): Raw source for this stage91 missing_format_vars (list(str)): List of all missing format92 variables for this stage93 line_start (int): Source line of this stage94 """95 if line_start:96 tw.line(97 "Source test stage (line {}):".format(line_start), white=True, bold=True98 )99 else:100 tw.line("Source test stages:", white=True, bold=True)101 for line in code_lines:102 if any(i in line for i in missing_format_vars):103 tw.line(line, red=True)104 else:105 tw.line(line, white=True)106 def _print_formatted_stage(self, tw, stage):107 """Print the 'formatted' stage that Tavern will actually use to send the108 request/process the response109 Args:110 tw (TerminalWriter): Pytest TW instance111 stage (dict): The 'final' stage used by Tavern112 """113 tw.line("Formatted stage:", white=True, bold=True)114 # This will definitely exist115 formatted_lines = yaml.dump(stage, default_flow_style=False).split("\n")116 keys = self._get_available_format_keys()117 for line in formatted_lines:118 if not line:119 continue120 if "{}" not in line:121 line = format_keys(line, keys)122 tw.line(" {}".format(line), white=True)123 def _print_errors(self, tw):124 """Print any errors in the 'normal' Pytest style125 Args:126 tw (TerminalWriter): Pytest TW instance127 """128 tw.line("Errors:", white=True, bold=True)129 # Sort of hack, just use this to directly extract the exception format.130 # If this breaks in future, just re-implement it131 e = FormattedExcinfo()132 lines = e.get_exconly(self.exce)133 for line in lines:134 tw.line(line, red=True, bold=True)135 def toterminal(self, tw):136 """Print out a custom error message to the terminal"""137 # Try to get the stage so we can print it out. I'm not sure if the stage138 # will ever NOT be present, but better to check just in case139 try:140 # pylint: disable=protected-access141 stage = self.exce._excinfo[1].stage142 except AttributeError:143 stage = None144 # Fallback, we don't know which stage it is145 stages = self.item.spec["stages"]146 first_line = start_mark(stages[0]).line - 1147 last_line = end_mark(stages[-1]).line148 line_start = None149 else:150 first_line, last_line, line_start = get_stage_lines(stage)151 code_lines = list(read_relevant_lines(self.item.spec, first_line, last_line))152 missing_format_vars = self._print_format_variables(tw, code_lines)153 tw.line("")154 self._print_test_stage(tw, code_lines, missing_format_vars, line_start)155 tw.line("")156 if not stage:157 tw.line("Stage not found", red=True, bold=True)158 elif missing_format_vars:159 tw.line("Missing format vars for stage", red=True, bold=True)160 else:161 self._print_formatted_stage(tw, stage)162 tw.line("")163 self._print_errors(tw)164 @property165 def longreprtext(self):166 tw = py.io.TerminalWriter(stringio=True) # pylint: disable=no-member167 tw.hasmarkup = False168 self.toterminal(tw)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tavern automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful