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

Function wrap_pytest_function_for_tracing

src/_pytest/debugging.py:311–327  ·  view source on GitHub ↗

Change the Python function object of the given Function item by a wrapper which actually enters pdb before calling the python function itself, effectively leaving the user in the pdb prompt in the first statement of the function.

(pyfuncitem)

Source from the content-addressed store, hash-verified

309
310
311def wrap_pytest_function_for_tracing(pyfuncitem) -> None:
312 """Change the Python function object of the given Function item by a
313 wrapper which actually enters pdb before calling the python function
314 itself, effectively leaving the user in the pdb prompt in the first
315 statement of the function."""
316 _pdb = pytestPDB._init_pdb("runcall")
317 testfunction = pyfuncitem.obj
318
319 # we can't just return `partial(pdb.runcall, testfunction)` because (on
320 # python < 3.7.4) runcall's first param is `func`, which means we'd get
321 # an exception if one of the kwargs to testfunction was called `func`.
322 @functools.wraps(testfunction)
323 def wrapper(*args, **kwargs) -> None:
324 func = functools.partial(testfunction, *args, **kwargs)
325 _pdb.runcall(func)
326
327 pyfuncitem.obj = wrapper
328
329
330def maybe_wrap_pytest_function_for_tracing(pyfuncitem) -> None:

Callers 2

pytest_pyfunc_callMethod · 0.85

Calls 1

_init_pdbMethod · 0.80

Tested by

no test coverage detected