summaryrefslogtreecommitdiff
path: root/src/_pytest/debugging.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-02-28 18:10:57 +0100
committerDaniel Hahler <git@thequod.de>2019-03-01 15:20:04 +0100
commitf7a3e001f74a53411f0ee682eed04eef0a0bfc30 (patch)
treefc3412d4ce9199d72e8979b4889e06e7f2cfbba2 /src/_pytest/debugging.py
parenta868a9ac13a2ac4a021a09c926b2564dccdfc70f (diff)
downloadpytest-f7a3e001f74a53411f0ee682eed04eef0a0bfc30.tar.gz
pdb: allow for --pdbclass=mod:attr.class
Diffstat (limited to 'src/_pytest/debugging.py')
-rw-r--r--src/_pytest/debugging.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py
index d37728a15..271a590a1 100644
--- a/src/_pytest/debugging.py
+++ b/src/_pytest/debugging.py
@@ -12,25 +12,32 @@ from _pytest import outcomes
from _pytest.config import hookimpl
-def pytest_addoption(parser):
- def validate_usepdb_cls(value):
- try:
- modname, classname = value.split(":")
- except ValueError:
- raise argparse.ArgumentTypeError(
- "{!r} is not in the format 'modname:classname'".format(value)
- )
-
- try:
- __import__(modname)
- pdb_cls = getattr(sys.modules[modname], classname)
- except Exception as exc:
- raise argparse.ArgumentTypeError(
- "could not get pdb class for {!r}: {}".format(value, exc)
- )
+def _validate_usepdb_cls(value):
+ try:
+ modname, classname = value.split(":")
+ except ValueError:
+ raise argparse.ArgumentTypeError(
+ "{!r} is not in the format 'modname:classname'".format(value)
+ )
+
+ try:
+ __import__(modname)
+ mod = sys.modules[modname]
+
+ # Handle --pdbcls=pdb:pdb.Pdb (useful e.g. with pdbpp).
+ parts = classname.split(".")
+ pdb_cls = getattr(mod, parts[0])
+ for part in parts[1:]:
+ pdb_cls = getattr(pdb_cls, part)
return pdb_cls
+ except Exception as exc:
+ raise argparse.ArgumentTypeError(
+ "could not get pdb class for {!r}: {}".format(value, exc)
+ )
+
+def pytest_addoption(parser):
group = parser.getgroup("general")
group._addoption(
"--pdb",
@@ -42,7 +49,7 @@ def pytest_addoption(parser):
"--pdbcls",
dest="usepdb_cls",
metavar="modulename:classname",
- type=validate_usepdb_cls,
+ type=_validate_usepdb_cls,
help="start a custom interactive Python debugger on errors. "
"For example: --pdbcls=IPython.terminal.debugger:TerminalPdb",
)