Add tests for custom pdb class.

(and edit CHANGELOG)
This commit is contained in:
Antony Lee 2016-07-11 17:43:06 -07:00
parent 6383b53ad9
commit 7ee3dd1cb5
3 changed files with 31 additions and 4 deletions

View File

@ -116,7 +116,8 @@
Example '-o xfail_strict=True'. A complete ini-options can be viewed
by py.test --help. Thanks `@blueyed`_ and `@fengxx`_ for the PR
*
* Allow passing a custom debugger class (e.g. ``IPython.core.debugger:Pdb``
via ``--pdbcls``). Thanks to `@anntzer`_ for the PR.
*
@ -185,8 +186,7 @@
Before, you only got exceptions later from ``argparse`` library,
giving no clue about the actual reason for double-added options.
* Allow passing a custom debugger class (e.g. ``IPython.core.debugger:Pdb``
via ``--pdbcls``.
*
*
@ -266,6 +266,7 @@
.. _@DRMacIver: https://github.com/DRMacIver
.. _@RedBeardCode: https://github.com/RedBeardCode
.. _@Vogtinator: https://github.com/Vogtinator
.. _@anntzer: https://github.com/anntzer
.. _@bagerard: https://github.com/bagerard
.. _@blueyed: https://github.com/blueyed
.. _@ceridwen: https://github.com/ceridwen

View File

@ -13,7 +13,8 @@ def pytest_addoption(parser):
help="start the interactive Python debugger on errors.")
group._addoption(
'--pdbcls', dest="usepdb_cls", metavar="modulename:classname",
help="start a custom interactive Python debugger on errors.")
help="start a custom interactive Python debugger on errors. "
"For example: --pdbcls=IPython.core.debugger:Pdb")
def pytest_namespace():
return {'set_trace': pytestPDB().set_trace}

View File

@ -311,3 +311,28 @@ class TestPDB:
child.sendeof()
if child.isalive():
child.wait()
def test_pdb_custom_cls(self, testdir):
called = []
# install dummy debugger class and track which methods were called on it
class _CustomPdb:
def __init__(self, *args, **kwargs):
called.append("init")
def reset(self):
called.append("reset")
def interaction(self, *args):
called.append("interaction")
_pytest._CustomPdb = _CustomPdb
p1 = testdir.makepyfile("""xxx """)
result = testdir.runpytest_inprocess(
"--pdbcls=_pytest:_CustomPdb", p1)
result.stdout.fnmatch_lines([
"*NameError*xxx*",
"*1 error*",
])
assert called == ["init", "reset", "interaction"]