MCPcopy Index your code
hub / github.com/ipython/ipython / repr_failure

Method repr_failure

IPython/testing/plugin/pytest_ipdoctest.py:387–449  ·  view source on GitHub ↗
(  # type: ignore[override]
        self,
        excinfo: ExceptionInfo[BaseException],
    )

Source from the content-addressed store, hash-verified

385
386 # TODO: Type ignored -- breaks Liskov Substitution.
387 def repr_failure( # type: ignore[override]
388 self,
389 excinfo: ExceptionInfo[BaseException],
390 ) -> Union[str, TerminalRepr]:
391 import doctest
392
393 failures: Optional[
394 Sequence[Union[doctest.DocTestFailure, doctest.UnexpectedException]]
395 ] = None
396 if isinstance(
397 excinfo.value, (doctest.DocTestFailure, doctest.UnexpectedException)
398 ):
399 failures = [excinfo.value]
400 elif isinstance(excinfo.value, MultipleDoctestFailures):
401 failures = excinfo.value.failures
402
403 if failures is None:
404 return super().repr_failure(excinfo)
405
406 reprlocation_lines = []
407 for failure in failures:
408 example = failure.example
409 test = failure.test
410 filename = test.filename
411 if test.lineno is None:
412 lineno = None
413 else:
414 lineno = test.lineno + example.lineno + 1
415 message = type(failure).__name__
416 # TODO: ReprFileLocation doesn't expect a None lineno.
417 reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type]
418 checker = _get_checker()
419 report_choice = _get_report_choice(self.config.getoption("ipdoctestreport"))
420 if lineno is not None:
421 assert failure.test.docstring is not None
422 lines = failure.test.docstring.splitlines(False)
423 # add line numbers to the left of the error message
424 assert test.lineno is not None
425 lines = [
426 "%03d %s" % (i + test.lineno + 1, x) for (i, x) in enumerate(lines)
427 ]
428 # trim docstring error lines to 10
429 lines = lines[max(example.lineno - 9, 0) : example.lineno + 1]
430 else:
431 lines = [
432 "EXAMPLE LOCATION UNKNOWN, not showing all tests of that example"
433 ]
434 indent = ">>>"
435 for line in example.source.splitlines():
436 lines.append(f"??? {indent} {line}")
437 indent = "..."
438 if isinstance(failure, doctest.DocTestFailure):
439 lines += checker.output_difference(
440 example, failure.got, report_choice
441 ).split("\n")
442 else:
443 inner_excinfo = ExceptionInfo.from_exc_info(failure.exc_info)
444 lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)]

Callers

nothing calls this directly

Calls 4

_get_checkerFunction · 0.85
_get_report_choiceFunction · 0.85
ReprFailDoctestClass · 0.85
format_exceptionMethod · 0.45

Tested by

no test coverage detected