예제 #1
0
 def from_item_and_call(cls, item: Item, call: "CallInfo[None]") -> "TestReport":
     """Create and fill a TestReport with standard item and call info."""
     when = call.when
     # Remove "collect" from the Literal type -- only for collection calls.
     assert when != "collect"
     duration = call.duration
     keywords = {x: 1 for x in item.keywords}
     excinfo = call.excinfo
     sections = []
     if not call.excinfo:
         outcome: Literal["passed", "failed", "skipped"] = "passed"
         longrepr: Union[
             None,
             ExceptionInfo[BaseException],
             Tuple[str, int, str],
             str,
             TerminalRepr,
         ] = None
     else:
         if not isinstance(excinfo, ExceptionInfo):
             outcome = "failed"
             longrepr = excinfo
         elif isinstance(excinfo.value, skip.Exception):
             outcome = "skipped"
             r = excinfo._getreprcrash()
             if excinfo.value._use_item_location:
                 filename, line = item.reportinfo()[:2]
                 assert line is not None
                 longrepr = str(filename), line + 1, r.message
             else:
                 longrepr = (str(r.path), r.lineno, r.message)
         else:
             outcome = "failed"
             if call.when == "call":
                 longrepr = item.repr_failure(excinfo)
             else:  # exception in setup or teardown
                 longrepr = item._repr_failure_py(
                     excinfo, style=item.config.getoption("tbstyle", "auto")
                 )
     for rwhen, key, content in item._report_sections:
         sections.append((f"Captured {key} {rwhen}", content))
     return cls(
         item.nodeid,
         item.location,
         keywords,
         outcome,
         longrepr,
         when,
         sections,
         duration,
         user_properties=item.user_properties,
     )
예제 #2
0
 def from_item_and_call(cls, item: Item,
                        call: "CallInfo[None]") -> "TestReport":
     """
     Factory method to create and fill a TestReport with standard item and call info.
     """
     when = call.when
     # Remove "collect" from the Literal type -- only for collection calls.
     assert when != "collect"
     duration = call.duration
     keywords = {x: 1 for x in item.keywords}
     excinfo = call.excinfo
     sections = []
     if not call.excinfo:
         outcome = "passed"  # type: Literal["passed", "failed", "skipped"]
         # TODO: Improve this Any.
         longrepr = None  # type: Optional[Any]
     else:
         if not isinstance(excinfo, ExceptionInfo):
             outcome = "failed"
             longrepr = excinfo
         elif excinfo.errisinstance(skip.Exception):
             outcome = "skipped"
             r = excinfo._getreprcrash()
             longrepr = (str(r.path), r.lineno, r.message)
         else:
             outcome = "failed"
             if call.when == "call":
                 longrepr = item.repr_failure(excinfo)
             else:  # exception in setup or teardown
                 longrepr = item._repr_failure_py(
                     excinfo,
                     style=item.config.getoption("tbstyle", "auto"))
     for rwhen, key, content in item._report_sections:
         sections.append(("Captured {} {}".format(key, rwhen), content))
     return cls(
         item.nodeid,
         item.location,
         keywords,
         outcome,
         longrepr,
         when,
         sections,
         duration,
         user_properties=item.user_properties,
     )