Skip to content

Commit

Permalink
use functools
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Oct 30, 2019
1 parent 3844cec commit 94ac6bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
13 changes: 3 additions & 10 deletions src/_pytest/debugging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" interactive debugging with PDB, the Python Debugger. """
import argparse
import functools
import pdb
import sys
from doctest import UnexpectedException
Expand Down Expand Up @@ -274,16 +275,8 @@ def pytest_pyfunc_call(self, pyfuncitem):
def _test_pytest_function(pyfuncitem):
_pdb = pytestPDB._init_pdb("runcall")
testfunction = pyfuncitem.obj
pyfuncitem.obj = _pdb.runcall
if "func" in pyfuncitem.funcargs: # pragma: no branch
raise ValueError("--trace can't be used with a fixture named func!")
pyfuncitem.funcargs["func"] = testfunction
if "func" not in pyfuncitem._fixtureinfo.argnames:
# TODO: when using parameterized tests, the _fixtureinfo is shared
# that needs to move to FunctionDefinition
new_list = list(pyfuncitem._fixtureinfo.argnames)
new_list.append("func")
pyfuncitem._fixtureinfo.argnames = tuple(new_list)
pyfuncitem.obj = functools.partial(_pdb.runcall, testfunction)
pyfuncitem.obj.__name__ = testfunction.__name__


def _enter_pdb(node, excinfo, rep):
Expand Down
46 changes: 32 additions & 14 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,23 +1031,41 @@ def test_trace_with_parametrize_handles_shared_fixtureinfo(self, testdir):
import pytest
@pytest.mark.parametrize('myparam', [1,2])
def test_1(myparam):
assert True
def test_1(myparam, request):
assert myparam in (1, 2)
assert request.function.__name__ == "test_1"
@pytest.mark.parametrize('func', [1,2])
def test_func(func, request):
assert func in (1, 2)
assert request.function.__name__ == "test_func"
@pytest.mark.parametrize('myparam', [1,2])
def test_func_kw(myparam, request, func="func_kw"):
assert myparam in (1, 2)
assert func == "func_kw"
assert request.function.__name__ == "test_func_kw"
"""
)
child = testdir.spawn_pytest("--trace " + str(p1))
child.expect_exact("> PDB runcall (IO-capturing turned off) >")
child.expect_exact("test_1")
child.expect_exact("Pdb")
child.sendline("args")
child.expect_exact("myparam = 1\r\n")
child.sendline("c")
child.expect_exact("Pdb")
child.sendline("args")
child.expect_exact("myparam = 2\r\n")
child.sendline("c")
for func, argname in [
("test_1", "myparam"),
("test_func", "func"),
("test_func_kw", "myparam"),
]:
child.expect_exact("> PDB runcall (IO-capturing turned off) >")
child.expect_exact(func)
child.expect_exact("Pdb")
child.sendline("args")
child.expect_exact("{} = 1\r\n".format(argname))
child.sendline("c")
child.expect_exact("Pdb")
child.sendline("args")
child.expect_exact("{} = 2\r\n".format(argname))
child.sendline("c")
child.expect_exact("> PDB continue (IO-capturing resumed) >")
rest = child.read().decode("utf8")
assert "2 passed in" in rest
assert "6 passed in" in rest
assert "reading from stdin while output" not in rest
# Only printed once - not on stderr.
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
Expand Down Expand Up @@ -1178,7 +1196,7 @@ def set_trace(self, *args):
def runcall(self, *args, **kwds):
print("runcall_called", args, kwds)
assert "func" in kwds
assert "func" not in kwds
""",
)
result = testdir.runpytest(
Expand Down

0 comments on commit 94ac6bf

Please sign in to comment.