def test_repr_traceback_tbfilter(self, importasmod): mod = importasmod(""" def f(x): raise ValueError(x) def entry(): f(0) """) excinfo = py.test.raises(ValueError, mod.entry) p = FormattedExcinfo(tbfilter=True) reprtb = p.repr_traceback(excinfo) assert len(reprtb.reprentries) == 2 p = FormattedExcinfo(tbfilter=False) reprtb = p.repr_traceback(excinfo) assert len(reprtb.reprentries) == 3
def test_repr_traceback_with_invalid_cwd(self, importasmod, monkeypatch): mod = importasmod(""" def f(x): raise ValueError(x) def entry(): f(0) """) excinfo = py.test.raises(ValueError, mod.entry) p = FormattedExcinfo() def raiseos(): raise OSError(2) monkeypatch.setattr(py.std.os, 'getcwd', raiseos) assert p._makepath(__file__) == __file__ reprtb = p.repr_traceback(excinfo)
def test_repr_traceback_recursion(self, importasmod): mod = importasmod(""" def rec2(x): return rec1(x+1) def rec1(x): return rec2(x-1) def entry(): rec1(42) """) excinfo = py.test.raises(RuntimeError, mod.entry) for style in ("short", "long", "no"): p = FormattedExcinfo(style="short") reprtb = p.repr_traceback(excinfo) assert reprtb.extraline == "!!! Recursion detected (same locals & position)" assert str(reprtb)
def test_repr_traceback_and_excinfo(self, importasmod): mod = importasmod(""" def f(x): raise ValueError(x) def entry(): f(0) """) excinfo = py.test.raises(ValueError, mod.entry) for style in ("long", "short"): p = FormattedExcinfo(style=style) reprtb = p.repr_traceback(excinfo) assert len(reprtb.reprentries) == 2 assert reprtb.style == style assert not reprtb.extraline repr = p.repr_excinfo(excinfo) assert repr.reprtraceback assert len(repr.reprtraceback.reprentries) == len(reprtb.reprentries) assert repr.reprcrash.path.endswith("mod.py") assert repr.reprcrash.message == "ValueError: 0"