Skip to content

Commit

Permalink
Merge pull request pytest-dev#5074 from blueyed/trace
Browse files Browse the repository at this point in the history
pdb: add test for --trace with --pdbcls
  • Loading branch information
blueyed committed Apr 8, 2019
2 parents b549438 + 4fb7a91 commit 3fa329c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/_pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _test_pytest_function(pyfuncitem):
_pdb = pytestPDB._init_pdb()
testfunction = pyfuncitem.obj
pyfuncitem.obj = _pdb.runcall
if "func" in pyfuncitem._fixtureinfo.argnames: # noqa
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)
Expand Down
15 changes: 13 additions & 2 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,11 @@ def test():
class Wrapped:
class MyPdb:
def set_trace(self, *args):
print("mypdb_called", args)
print("settrace_called", args)
def runcall(self, *args, **kwds):
print("runcall_called", args, kwds)
assert "func" in kwds
""",
)
result = testdir.runpytest(
Expand All @@ -1165,4 +1169,11 @@ def set_trace(self, *args):
str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", syspathinsert=True
)
assert result.ret == 0
result.stdout.fnmatch_lines(["*mypdb_called*", "* 1 passed in *"])
result.stdout.fnmatch_lines(["*settrace_called*", "* 1 passed in *"])

# Ensure that it also works with --trace.
result = testdir.runpytest(
str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", "--trace", syspathinsert=True
)
assert result.ret == 0
result.stdout.fnmatch_lines(["*runcall_called*", "* 1 passed in *"])

0 comments on commit 3fa329c

Please sign in to comment.