Call func, wrapping the result in a CallInfo. :param func: The function to call. Called without arguments. :param when: The phase in which the function is called. :param reraise: Exception or exceptions that shall propagate if raised by th
(
cls,
func: "Callable[[], TResult]",
when: "Literal['collect', 'setup', 'call', 'teardown']",
reraise: Optional[
Union[Type[BaseException], Tuple[Type[BaseException], ...]]
] = None,
)
| 316 | |
| 317 | @classmethod |
| 318 | def from_call( |
| 319 | cls, |
| 320 | func: "Callable[[], TResult]", |
| 321 | when: "Literal['collect', 'setup', 'call', 'teardown']", |
| 322 | reraise: Optional[ |
| 323 | Union[Type[BaseException], Tuple[Type[BaseException], ...]] |
| 324 | ] = None, |
| 325 | ) -> "CallInfo[TResult]": |
| 326 | """Call func, wrapping the result in a CallInfo. |
| 327 | |
| 328 | :param func: |
| 329 | The function to call. Called without arguments. |
| 330 | :param when: |
| 331 | The phase in which the function is called. |
| 332 | :param reraise: |
| 333 | Exception or exceptions that shall propagate if raised by the |
| 334 | function, instead of being wrapped in the CallInfo. |
| 335 | """ |
| 336 | excinfo = None |
| 337 | start = timing.time() |
| 338 | precise_start = timing.perf_counter() |
| 339 | try: |
| 340 | result: Optional[TResult] = func() |
| 341 | except BaseException: |
| 342 | excinfo = ExceptionInfo.from_current() |
| 343 | if reraise is not None and isinstance(excinfo.value, reraise): |
| 344 | raise |
| 345 | result = None |
| 346 | # use the perf counter |
| 347 | precise_stop = timing.perf_counter() |
| 348 | duration = precise_stop - precise_start |
| 349 | stop = timing.time() |
| 350 | return cls( |
| 351 | start=start, |
| 352 | stop=stop, |
| 353 | duration=duration, |
| 354 | when=when, |
| 355 | result=result, |
| 356 | excinfo=excinfo, |
| 357 | _ispytest=True, |
| 358 | ) |
| 359 | |
| 360 | def __repr__(self) -> str: |
| 361 | if self.excinfo is None: |