From 7ee3dd1cb5e40056283f1b2b39c2586429ac55bf Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 11 Jul 2016 17:43:06 -0700 Subject: [PATCH] Add tests for custom pdb class. (and edit CHANGELOG) --- CHANGELOG.rst | 7 ++++--- _pytest/debugging.py | 3 ++- testing/test_pdb.py | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8d00c18d0..d56161e20 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/_pytest/debugging.py b/_pytest/debugging.py index dca2978a9..d8cd5a4e3 100644 --- a/_pytest/debugging.py +++ b/_pytest/debugging.py @@ -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} diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 44163a204..6df2b496f 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -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"]