Best Python code snippet using tavern
error.py
Source:error.py
...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)169 exc = tw.stringio.getvalue()170 return exc.strip()171 def __str__(self):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!