MCPcopy Create free account
hub / github.com/pytest-dev/pytest / wrap_pytest_function_for_tracing

Function wrap_pytest_function_for_tracing

src/_pytest/debugging.py:310–326  ·  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

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

Callers 2

pytest_pyfunc_callMethod · 0.85

Calls 1

_init_pdbMethod · 0.80

Tested by

no test coverage detected