From c478027805539cc3cbef11ebe830caf6c748b808 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 6 Sep 2013 15:29:00 +0200 Subject: [PATCH] make "import pdb ; pdb.set_trace()" work natively wrt capturing (no "-s" needed anymore), turning ``pytest.set_trace()`` into a mere shortcut. --- CHANGELOG | 3 +++ _pytest/pdb.py | 6 ++++++ testing/test_pdb.py | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 74841bfec..cd46a64ea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ 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 on internal errors) . This was implemented by a slight internal refactoring and the introduction of a new hook diff --git a/_pytest/pdb.py b/_pytest/pdb.py index 8c243ef9f..6405773f8 100644 --- a/_pytest/pdb.py +++ b/_pytest/pdb.py @@ -16,6 +16,12 @@ def pytest_configure(config): if config.getvalue("usepdb"): 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: """ Pseudo PDB that defers to the real pdb. """ item = None diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 517b13400..b5dd8df2b 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -134,6 +134,22 @@ class TestPDB: if child.isalive(): 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): p1 = testdir.makepyfile(""" import pytest