summaryrefslogtreecommitdiff
path: root/testing/test_pdb.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2018-11-18 20:18:42 +0100
committerDaniel Hahler <git@thequod.de>2018-11-19 13:04:14 +0100
commit92a2884b09eb793a390460012e6e2859da87767a (patch)
tree5ae85c0762276d4e7aec5862f7fd98e72387d99d /testing/test_pdb.py
parent62967b311029b7a3e022d35dc57d2b8b1199b57f (diff)
downloadpytest-92a2884b09eb793a390460012e6e2859da87767a.tar.gz
pdb: support kwargs with `pdb.set_trace`
This handles `header` similar to Python 3.7 does it, and forwards any other keyword arguments to the Pdb constructor. This allows for `__import__("pdb").set_trace(skip=["foo.*"])`. Fixes https://github.com/pytest-dev/pytest/issues/4416.
Diffstat (limited to 'testing/test_pdb.py')
-rw-r--r--testing/test_pdb.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/testing/test_pdb.py b/testing/test_pdb.py
index dd349454b..41b4badda 100644
--- a/testing/test_pdb.py
+++ b/testing/test_pdb.py
@@ -390,6 +390,28 @@ class TestPDB(object):
assert "hello17" in rest # out is captured
self.flush(child)
+ def test_pdb_set_trace_kwargs(self, testdir):
+ p1 = testdir.makepyfile(
+ """
+ import pytest
+ def test_1():
+ i = 0
+ print("hello17")
+ pytest.set_trace(header="== my_header ==")
+ x = 3
+ """
+ )
+ child = testdir.spawn_pytest(str(p1))
+ child.expect("== my_header ==")
+ assert "PDB set_trace" not in child.before.decode()
+ child.expect("Pdb")
+ child.sendeof()
+ rest = child.read().decode("utf-8")
+ assert "1 failed" in rest
+ assert "def test_1" in rest
+ assert "hello17" in rest # out is captured
+ self.flush(child)
+
def test_pdb_set_trace_interception(self, testdir):
p1 = testdir.makepyfile(
"""
@@ -634,6 +656,12 @@ class TestPDB(object):
testdir.makepyfile(
custom_pdb="""
class CustomPdb(object):
+ def __init__(self, *args, **kwargs):
+ skip = kwargs.pop("skip")
+ assert skip == ["foo.*"]
+ print("__init__")
+ super(CustomPdb, self).__init__(*args, **kwargs)
+
def set_trace(*args, **kwargs):
print('custom set_trace>')
"""
@@ -643,12 +671,13 @@ class TestPDB(object):
import pytest
def test_foo():
- pytest.set_trace()
+ pytest.set_trace(skip=['foo.*'])
"""
)
monkeypatch.setenv("PYTHONPATH", str(testdir.tmpdir))
child = testdir.spawn_pytest("--pdbcls=custom_pdb:CustomPdb %s" % str(p1))
+ child.expect("__init__")
child.expect("custom set_trace>")
self.flush(child)