From c7326f1949f66ac2287089c3d9ecec2a9d75b8b5 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 8 Feb 2010 14:17:01 +0100 Subject: [PATCH] fix a pdb problem when dropping to a "raises" related failure --HG-- branch : trunk --- CHANGELOG | 2 ++ py/_plugin/pytest_pdb.py | 3 ++- testing/plugin/test_pytest_pdb.py | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 19442995a..770198e7d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -29,6 +29,8 @@ Changes between 1.2.1 and 1.2.0 - fix issue63: assume <40 columns to be a bogus terminal width, default to 80 +- fix pdb debugging to be in the correct frame on raises-related errors + - update apipkg.py to fix an issue where recursive imports might unnecessarily break importing diff --git a/py/_plugin/pytest_pdb.py b/py/_plugin/pytest_pdb.py index 8ee157efb..1c5884920 100644 --- a/py/_plugin/pytest_pdb.py +++ b/py/_plugin/pytest_pdb.py @@ -91,10 +91,11 @@ class Pdb(py.std.pdb.Pdb): stack, i = pdb.Pdb.get_stack(self, f, t) if f is None: i = max(0, len(stack) - 1) + while i and stack[i][0].f_locals.get("__tracebackhide__", False): + i-=1 return stack, i def post_mortem(t): - # modified from pdb.py for the new get_stack() implementation p = Pdb() p.reset() p.interaction(None, t) diff --git a/testing/plugin/test_pytest_pdb.py b/testing/plugin/test_pytest_pdb.py index bfe1a1d43..dfc1c9955 100644 --- a/testing/plugin/test_pytest_pdb.py +++ b/testing/plugin/test_pytest_pdb.py @@ -43,3 +43,22 @@ class TestPDB: child.expect("1 failed") if child.isalive(): child.wait() + + def test_pdb_interaction_exception(self, testdir): + p1 = testdir.makepyfile(""" + import py + def globalfunc(): + pass + def test_1(): + py.test.raises(ValueError, globalfunc) + """) + child = testdir.spawn_pytest("--pdb %s" % p1) + child.expect(".*def test_1") + child.expect(".*py.test.raises.*globalfunc") + child.expect("(Pdb)") + child.sendline("globalfunc") + child.expect(".*function") + child.sendeof() + child.expect("1 failed") + if child.isalive(): + child.wait()