Skip to content

Commit 7ee3dd1

Browse files
committed
Add tests for custom pdb class.
(and edit CHANGELOG)
1 parent 6383b53 commit 7ee3dd1

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
Example '-o xfail_strict=True'. A complete ini-options can be viewed
117117
by py.test --help. Thanks `@blueyed`_ and `@fengxx`_ for the PR
118118

119-
*
119+
* Allow passing a custom debugger class (e.g. ``IPython.core.debugger:Pdb``
120+
via ``--pdbcls``). Thanks to `@anntzer`_ for the PR.
120121

121122
*
122123

@@ -185,8 +186,7 @@
185186
Before, you only got exceptions later from ``argparse`` library,
186187
giving no clue about the actual reason for double-added options.
187188

188-
* Allow passing a custom debugger class (e.g. ``IPython.core.debugger:Pdb``
189-
via ``--pdbcls``.
189+
*
190190

191191
*
192192

@@ -266,6 +266,7 @@
266266
.. _@DRMacIver: https://github.com/DRMacIver
267267
.. _@RedBeardCode: https://github.com/RedBeardCode
268268
.. _@Vogtinator: https://github.com/Vogtinator
269+
.. _@anntzer: https://github.com/anntzer
269270
.. _@bagerard: https://github.com/bagerard
270271
.. _@blueyed: https://github.com/blueyed
271272
.. _@ceridwen: https://github.com/ceridwen

_pytest/debugging.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def pytest_addoption(parser):
1313
help="start the interactive Python debugger on errors.")
1414
group._addoption(
1515
'--pdbcls', dest="usepdb_cls", metavar="modulename:classname",
16-
help="start a custom interactive Python debugger on errors.")
16+
help="start a custom interactive Python debugger on errors. "
17+
"For example: --pdbcls=IPython.core.debugger:Pdb")
1718

1819
def pytest_namespace():
1920
return {'set_trace': pytestPDB().set_trace}

testing/test_pdb.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,28 @@ def test_foo():
311311
child.sendeof()
312312
if child.isalive():
313313
child.wait()
314+
315+
def test_pdb_custom_cls(self, testdir):
316+
called = []
317+
318+
# install dummy debugger class and track which methods were called on it
319+
class _CustomPdb:
320+
def __init__(self, *args, **kwargs):
321+
called.append("init")
322+
323+
def reset(self):
324+
called.append("reset")
325+
326+
def interaction(self, *args):
327+
called.append("interaction")
328+
329+
_pytest._CustomPdb = _CustomPdb
330+
331+
p1 = testdir.makepyfile("""xxx """)
332+
result = testdir.runpytest_inprocess(
333+
"--pdbcls=_pytest:_CustomPdb", p1)
334+
result.stdout.fnmatch_lines([
335+
"*NameError*xxx*",
336+
"*1 error*",
337+
])
338+
assert called == ["init", "reset", "interaction"]

0 commit comments

Comments
 (0)