MCPcopy
hub / github.com/pytest-dev/pytest / from_call

Method from_call

src/_pytest/runner.py:341–376  ·  view source on GitHub ↗

Call func, wrapping the result in a CallInfo. :param func: The function to call. Called without arguments. :type func: Callable[[], _pytest.runner.TResult] :param when: The phase in which the function is called. :param reraise: Exc

(
        cls,
        func: Callable[[], TResult],
        when: Literal["collect", "setup", "call", "teardown"],
        reraise: type[BaseException] | tuple[type[BaseException], ...] | None = None,
    )

Source from the content-addressed store, hash-verified

339
340 @classmethod
341 def from_call(
342 cls,
343 func: Callable[[], TResult],
344 when: Literal["collect", "setup", "call", "teardown"],
345 reraise: type[BaseException] | tuple[type[BaseException], ...] | None = None,
346 ) -> CallInfo[TResult]:
347 """Call func, wrapping the result in a CallInfo.
348
349 :param func:
350 The function to call. Called without arguments.
351 :type func: Callable[[], _pytest.runner.TResult]
352 :param when:
353 The phase in which the function is called.
354 :param reraise:
355 Exception or exceptions that shall propagate if raised by the
356 function, instead of being wrapped in the CallInfo.
357 """
358 excinfo = None
359 instant = timing.Instant()
360 try:
361 result: TResult | None = func()
362 except BaseException:
363 excinfo = ExceptionInfo.from_current()
364 if reraise is not None and isinstance(excinfo.value, reraise):
365 raise
366 result = None
367 duration = instant.elapsed()
368 return cls(
369 start=duration.start.time,
370 stop=duration.stop.time,
371 duration=duration.seconds,
372 when=when,
373 result=result,
374 excinfo=excinfo,
375 _ispytest=True,
376 )
377
378 def __repr__(self) -> str:
379 if self.excinfo is None:

Callers 4

call_and_reportFunction · 0.80
test_callinfoFunction · 0.80

Calls 4

elapsedMethod · 0.95
clsFunction · 0.85
from_currentMethod · 0.80
funcFunction · 0.50

Tested by 2

test_callinfoFunction · 0.64