Skip to content

Commit 94ac6bf

Browse files
committed
use functools
1 parent 3844cec commit 94ac6bf

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

src/_pytest/debugging.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" interactive debugging with PDB, the Python Debugger. """
22
import argparse
3+
import functools
34
import pdb
45
import sys
56
from doctest import UnexpectedException
@@ -274,16 +275,8 @@ def pytest_pyfunc_call(self, pyfuncitem):
274275
def _test_pytest_function(pyfuncitem):
275276
_pdb = pytestPDB._init_pdb("runcall")
276277
testfunction = pyfuncitem.obj
277-
pyfuncitem.obj = _pdb.runcall
278-
if "func" in pyfuncitem.funcargs: # pragma: no branch
279-
raise ValueError("--trace can't be used with a fixture named func!")
280-
pyfuncitem.funcargs["func"] = testfunction
281-
if "func" not in pyfuncitem._fixtureinfo.argnames:
282-
# TODO: when using parameterized tests, the _fixtureinfo is shared
283-
# that needs to move to FunctionDefinition
284-
new_list = list(pyfuncitem._fixtureinfo.argnames)
285-
new_list.append("func")
286-
pyfuncitem._fixtureinfo.argnames = tuple(new_list)
278+
pyfuncitem.obj = functools.partial(_pdb.runcall, testfunction)
279+
pyfuncitem.obj.__name__ = testfunction.__name__
287280

288281

289282
def _enter_pdb(node, excinfo, rep):

testing/test_pdb.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,23 +1031,41 @@ def test_trace_with_parametrize_handles_shared_fixtureinfo(self, testdir):
10311031
import pytest
10321032
10331033
@pytest.mark.parametrize('myparam', [1,2])
1034-
def test_1(myparam):
1035-
assert True
1034+
def test_1(myparam, request):
1035+
assert myparam in (1, 2)
1036+
assert request.function.__name__ == "test_1"
1037+
1038+
@pytest.mark.parametrize('func', [1,2])
1039+
def test_func(func, request):
1040+
assert func in (1, 2)
1041+
assert request.function.__name__ == "test_func"
1042+
1043+
@pytest.mark.parametrize('myparam', [1,2])
1044+
def test_func_kw(myparam, request, func="func_kw"):
1045+
assert myparam in (1, 2)
1046+
assert func == "func_kw"
1047+
assert request.function.__name__ == "test_func_kw"
10361048
"""
10371049
)
10381050
child = testdir.spawn_pytest("--trace " + str(p1))
1039-
child.expect_exact("> PDB runcall (IO-capturing turned off) >")
1040-
child.expect_exact("test_1")
1041-
child.expect_exact("Pdb")
1042-
child.sendline("args")
1043-
child.expect_exact("myparam = 1\r\n")
1044-
child.sendline("c")
1045-
child.expect_exact("Pdb")
1046-
child.sendline("args")
1047-
child.expect_exact("myparam = 2\r\n")
1048-
child.sendline("c")
1051+
for func, argname in [
1052+
("test_1", "myparam"),
1053+
("test_func", "func"),
1054+
("test_func_kw", "myparam"),
1055+
]:
1056+
child.expect_exact("> PDB runcall (IO-capturing turned off) >")
1057+
child.expect_exact(func)
1058+
child.expect_exact("Pdb")
1059+
child.sendline("args")
1060+
child.expect_exact("{} = 1\r\n".format(argname))
1061+
child.sendline("c")
1062+
child.expect_exact("Pdb")
1063+
child.sendline("args")
1064+
child.expect_exact("{} = 2\r\n".format(argname))
1065+
child.sendline("c")
1066+
child.expect_exact("> PDB continue (IO-capturing resumed) >")
10491067
rest = child.read().decode("utf8")
1050-
assert "2 passed in" in rest
1068+
assert "6 passed in" in rest
10511069
assert "reading from stdin while output" not in rest
10521070
# Only printed once - not on stderr.
10531071
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
@@ -1178,7 +1196,7 @@ def set_trace(self, *args):
11781196
11791197
def runcall(self, *args, **kwds):
11801198
print("runcall_called", args, kwds)
1181-
assert "func" in kwds
1199+
assert "func" not in kwds
11821200
""",
11831201
)
11841202
result = testdir.runpytest(

0 commit comments

Comments
 (0)