Merge pull request #4419 from blueyed/set_trace-kwargs
pdb: support kwargs with `pdb.set_trace`
This commit is contained in:
@@ -389,6 +389,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(
|
||||
"""
|
||||
@@ -633,6 +655,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>')
|
||||
"""
|
||||
@@ -642,12 +670,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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user