summaryrefslogtreecommitdiff
path: root/src/_pytest/debugging.py
diff options
context:
space:
mode:
authorDavid Szotten <davidszotten@gmail.com>2019-10-28 21:48:51 +0000
committerDavid Szotten <davidszotten@gmail.com>2019-10-31 21:41:33 +0000
commit285524c6cdde61fde3d9b4f250b4fa9bbb46e932 (patch)
treedbed8e9a9ddd21bc2260fd4e2056366f59f1c144 /src/_pytest/debugging.py
parentcefe6bfec38f8f9e200b2e233a840cf1de2bf3b4 (diff)
downloadpytest-285524c6cdde61fde3d9b4f250b4fa9bbb46e932.tar.gz
Fix --trace for parametrized tests
Without this, the second time it tries to stop in a parametrized function it raises instead: `ValueError: --trace can't be used with a fixture named func!` Implementation idea, test (and changelog tweaks) thanks to blueyed Co-Authored-By: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> Co-Authored-By: Daniel Hahler <git@thequod.de>
Diffstat (limited to 'src/_pytest/debugging.py')
-rw-r--r--src/_pytest/debugging.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py
index 2e3d49c37..3f3c58b16 100644
--- a/src/_pytest/debugging.py
+++ b/src/_pytest/debugging.py
@@ -1,5 +1,6 @@
""" interactive debugging with PDB, the Python Debugger. """
import argparse
+import functools
import pdb
import sys
from doctest import UnexpectedException
@@ -274,13 +275,16 @@ class PdbTrace:
def _test_pytest_function(pyfuncitem):
_pdb = pytestPDB._init_pdb("runcall")
testfunction = pyfuncitem.obj
- pyfuncitem.obj = _pdb.runcall
- if "func" in pyfuncitem._fixtureinfo.argnames: # pragma: no branch
- raise ValueError("--trace can't be used with a fixture named func!")
- pyfuncitem.funcargs["func"] = testfunction
- new_list = list(pyfuncitem._fixtureinfo.argnames)
- new_list.append("func")
- pyfuncitem._fixtureinfo.argnames = tuple(new_list)
+
+ # we can't just return `partial(pdb.runcall, testfunction)` because (on
+ # python < 3.7.4) runcall's first param is `func`, which means we'd get
+ # an exception if one of the kwargs to testfunction was called `func`
+ @functools.wraps(testfunction)
+ def wrapper(*args, **kwargs):
+ func = functools.partial(testfunction, *args, **kwargs)
+ _pdb.runcall(func)
+
+ pyfuncitem.obj = wrapper
def _enter_pdb(node, excinfo, rep):