unittest plugin: prune __unittest marked modules from traces

This commit is contained in:
Ronny Pfannschmidt 2011-03-05 17:49:51 +01:00
parent 7e44c38570
commit a6c518e68c
2 changed files with 16 additions and 0 deletions

View File

@ -102,6 +102,10 @@ class TestCaseFunction(pytest.Function):
def runtest(self):
self._testcase(result=self)
def _prunetraceback(self, excinfo):
pytest.Function._prunetraceback(self, excinfo)
excinfo.traceback = excinfo.traceback.filter(lambda x:not x.frame.f_globals.get('__unittest'))
@pytest.mark.tryfirst
def pytest_runtest_makereport(item, call):
if isinstance(item, TestCaseFunction):

View File

@ -396,3 +396,15 @@ def test_djangolike_testcase(testdir):
"*tearDown()*",
"*_post_teardown()*",
])
def test_unittest_not_shown_in_traceback(testdir):
testdir.makepyfile("""
import unittest
class t(unittest.TestCase):
def test_hello(self):
x = 3
self.assertEquals(x, 4)
""")
res = testdir.runpytest()
assert "failUnlessEqual" not in res.stdout.str()