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)
| 309 | |
| 310 | |
| 311 | def 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 | |
| 330 | def maybe_wrap_pytest_function_for_tracing(pyfuncitem) -> None: |
no test coverage detected