Create and fill a TestReport with standard item and call info. :param item: The item. :param call: The call info.
(cls, item: Item, call: CallInfo[None])
| 382 | |
| 383 | @classmethod |
| 384 | def from_item_and_call(cls, item: Item, call: CallInfo[None]) -> TestReport: |
| 385 | """Create and fill a TestReport with standard item and call info. |
| 386 | |
| 387 | :param item: The item. |
| 388 | :param call: The call info. |
| 389 | """ |
| 390 | when = call.when |
| 391 | # Remove "collect" from the Literal type -- only for collection calls. |
| 392 | assert when != "collect" |
| 393 | duration = call.duration |
| 394 | start = call.start |
| 395 | stop = call.stop |
| 396 | keywords = {x: 1 for x in item.keywords} |
| 397 | excinfo = call.excinfo |
| 398 | sections = [] |
| 399 | if not call.excinfo: |
| 400 | outcome: Literal["passed", "failed", "skipped"] = "passed" |
| 401 | longrepr: ( |
| 402 | None |
| 403 | | ExceptionInfo[BaseException] |
| 404 | | tuple[str, int, str] |
| 405 | | str |
| 406 | | TerminalRepr |
| 407 | ) = None |
| 408 | else: |
| 409 | if not isinstance(excinfo, ExceptionInfo): |
| 410 | outcome = "failed" |
| 411 | longrepr = excinfo |
| 412 | elif isinstance(excinfo.value, skip.Exception): |
| 413 | outcome = "skipped" |
| 414 | r = excinfo._getreprcrash() |
| 415 | assert r is not None, ( |
| 416 | "There should always be a traceback entry for skipping a test." |
| 417 | ) |
| 418 | if excinfo.value._use_item_location: |
| 419 | path, line = item.reportinfo()[:2] |
| 420 | assert line is not None |
| 421 | longrepr = (os.fspath(path), line + 1, r.message) |
| 422 | else: |
| 423 | longrepr = (str(r.path), r.lineno, r.message) |
| 424 | elif isinstance(excinfo.value, BaseExceptionGroup) and ( |
| 425 | excinfo.value.split(skip.Exception)[1] is None |
| 426 | ): |
| 427 | # All exceptions in the group are skip exceptions. |
| 428 | outcome = "skipped" |
| 429 | excinfo = cast( |
| 430 | ExceptionInfo[ |
| 431 | BaseExceptionGroup[BaseException | BaseExceptionGroup] |
| 432 | ], |
| 433 | excinfo, |
| 434 | ) |
| 435 | longrepr = _format_exception_group_all_skipped_longrepr(item, excinfo) |
| 436 | else: |
| 437 | outcome = "failed" |
| 438 | longrepr = _format_failed_longrepr(item, call, excinfo) |
| 439 | for rwhen, key, content in item._report_sections: |
| 440 | sections.append((f"Captured {key} {rwhen}", content)) |
| 441 | return cls( |
no test coverage detected