make "import pdb ; pdb.set_trace()" work natively wrt capturing (no "-s" needed

anymore), turning ``pytest.set_trace()`` into a mere shortcut.
This commit is contained in:
holger krekel 2013-09-06 15:29:00 +02:00
parent 109e2f215f
commit c478027805
3 changed files with 25 additions and 0 deletions

View File

@ -1,6 +1,9 @@
Changes between 2.3.5 and 2.4.DEV Changes between 2.3.5 and 2.4.DEV
----------------------------------- -----------------------------------
- make "import pdb ; pdb.set_trace()" work natively wrt capturing (no "-s" needed
anymore), making ``pytest.set_trace()`` a mere shortcut.
- fix issue181: --pdb now also works on collect errors (and - fix issue181: --pdb now also works on collect errors (and
on internal errors) . This was implemented by a slight internal on internal errors) . This was implemented by a slight internal
refactoring and the introduction of a new hook refactoring and the introduction of a new hook

View File

@ -16,6 +16,12 @@ def pytest_configure(config):
if config.getvalue("usepdb"): if config.getvalue("usepdb"):
config.pluginmanager.register(PdbInvoke(), 'pdbinvoke') config.pluginmanager.register(PdbInvoke(), 'pdbinvoke')
old_trace = py.std.pdb.set_trace
def fin():
py.std.pdb.set_trace = old_trace
py.std.pdb.set_trace = pytest.set_trace
config._cleanup.append(fin)
class pytestPDB: class pytestPDB:
""" Pseudo PDB that defers to the real pdb. """ """ Pseudo PDB that defers to the real pdb. """
item = None item = None

View File

@ -134,6 +134,22 @@ class TestPDB:
if child.isalive(): if child.isalive():
child.wait() child.wait()
def test_pdb_set_trace_interception(self, testdir):
p1 = testdir.makepyfile("""
import pdb
def test_1():
pdb.set_trace()
""")
child = testdir.spawn_pytest(str(p1))
child.expect("test_1")
child.expect("(Pdb)")
child.sendeof()
rest = child.read()
assert "1 failed" in rest
assert "reading from stdin while output" not in rest
if child.isalive():
child.wait()
def test_pdb_and_capsys(self, testdir): def test_pdb_and_capsys(self, testdir):
p1 = testdir.makepyfile(""" p1 = testdir.makepyfile("""
import pytest import pytest