Remove unnecessary else clause in repr_failure() (#8661)
* Remove unnecessary else clause in repr_failure() * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Zachary Kneupper <zacharykneupper@Zacharys-MBP.lan> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
3ae0103975
commit
48f14c48ea
|
@ -322,7 +322,9 @@ class DoctestItem(pytest.Item):
|
||||||
elif isinstance(excinfo.value, MultipleDoctestFailures):
|
elif isinstance(excinfo.value, MultipleDoctestFailures):
|
||||||
failures = excinfo.value.failures
|
failures = excinfo.value.failures
|
||||||
|
|
||||||
if failures is not None:
|
if failures is None:
|
||||||
|
return super().repr_failure(excinfo)
|
||||||
|
|
||||||
reprlocation_lines = []
|
reprlocation_lines = []
|
||||||
for failure in failures:
|
for failure in failures:
|
||||||
example = failure.example
|
example = failure.example
|
||||||
|
@ -336,17 +338,14 @@ class DoctestItem(pytest.Item):
|
||||||
# TODO: ReprFileLocation doesn't expect a None lineno.
|
# TODO: ReprFileLocation doesn't expect a None lineno.
|
||||||
reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type]
|
reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type]
|
||||||
checker = _get_checker()
|
checker = _get_checker()
|
||||||
report_choice = _get_report_choice(
|
report_choice = _get_report_choice(self.config.getoption("doctestreport"))
|
||||||
self.config.getoption("doctestreport")
|
|
||||||
)
|
|
||||||
if lineno is not None:
|
if lineno is not None:
|
||||||
assert failure.test.docstring is not None
|
assert failure.test.docstring is not None
|
||||||
lines = failure.test.docstring.splitlines(False)
|
lines = failure.test.docstring.splitlines(False)
|
||||||
# add line numbers to the left of the error message
|
# add line numbers to the left of the error message
|
||||||
assert test.lineno is not None
|
assert test.lineno is not None
|
||||||
lines = [
|
lines = [
|
||||||
"%03d %s" % (i + test.lineno + 1, x)
|
"%03d %s" % (i + test.lineno + 1, x) for (i, x) in enumerate(lines)
|
||||||
for (i, x) in enumerate(lines)
|
|
||||||
]
|
]
|
||||||
# trim docstring error lines to 10
|
# trim docstring error lines to 10
|
||||||
lines = lines[max(example.lineno - 9, 0) : example.lineno + 1]
|
lines = lines[max(example.lineno - 9, 0) : example.lineno + 1]
|
||||||
|
@ -366,13 +365,10 @@ class DoctestItem(pytest.Item):
|
||||||
inner_excinfo = ExceptionInfo.from_exc_info(failure.exc_info)
|
inner_excinfo = ExceptionInfo.from_exc_info(failure.exc_info)
|
||||||
lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)]
|
lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)]
|
||||||
lines += [
|
lines += [
|
||||||
x.strip("\n")
|
x.strip("\n") for x in traceback.format_exception(*failure.exc_info)
|
||||||
for x in traceback.format_exception(*failure.exc_info)
|
|
||||||
]
|
]
|
||||||
reprlocation_lines.append((reprlocation, lines))
|
reprlocation_lines.append((reprlocation, lines))
|
||||||
return ReprFailDoctest(reprlocation_lines)
|
return ReprFailDoctest(reprlocation_lines)
|
||||||
else:
|
|
||||||
return super().repr_failure(excinfo)
|
|
||||||
|
|
||||||
def reportinfo(self):
|
def reportinfo(self):
|
||||||
assert self.dtest is not None
|
assert self.dtest is not None
|
||||||
|
|
Loading…
Reference in New Issue