# HG changeset patch -- Bitbucket.org # Project pytest # URL http://bitbucket.org/hpk42/pytest/overview # User holger krekel <hol...@merlinux.eu> # Date 1290605704 -3600 # Node ID 84ce63c04007afe18d1491742bc3c56794a22658 # Parent 19df6d3f871fce3005bbef752f28249669233410 teach trial support code to throw separate errors/failures for setup/call/teardown
--- a/_pytest/unittest.py +++ b/_pytest/unittest.py @@ -47,7 +47,7 @@ class TestCaseFunction(pytest.Function): # unwrap potential exception info (see twisted trial support below) rawexcinfo = getattr(rawexcinfo, '_rawexcinfo', rawexcinfo) try: - self._excinfo = py.code.ExceptionInfo(rawexcinfo) + excinfo = py.code.ExceptionInfo(rawexcinfo) except TypeError: try: try: @@ -63,7 +63,8 @@ class TestCaseFunction(pytest.Function): except KeyboardInterrupt: raise except pytest.fail.Exception: - self._excinfo = py.code.ExceptionInfo() + excinfo = py.code.ExceptionInfo() + self.__dict__.setdefault('_excinfo', []).append(excinfo) def addError(self, testcase, rawexcinfo): self._addexcinfo(rawexcinfo) @@ -80,9 +81,8 @@ class TestCaseFunction(pytest.Function): @pytest.mark.tryfirst def pytest_runtest_makereport(item, call): if isinstance(item, TestCaseFunction): - if item._excinfo: - call.excinfo = item._excinfo - item._excinfo = None + if hasattr(item, '_excinfo') and item._excinfo: + call.excinfo = item._excinfo.pop(0) del call.result # twisted trial support --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -183,11 +183,9 @@ def test_testcase_totally_incompatible_e pass """) item.addError(None, 42) - excinfo = item._excinfo + excinfo = item._excinfo.pop(0) assert 'ERROR: Unknown Incompatible' in str(excinfo.getrepr()) - - class TestTrialUnittest: def setup_class(cls): pytest.importorskip("twisted.trial.unittest") @@ -225,6 +223,7 @@ class TestTrialUnittest: "*3 skipped*2 xfail*", ]) + @pytest.mark.xfail(reason="fijal needs add checks") def test_trial_error(self, testdir): testdir.makepyfile(""" from twisted.trial.unittest import TestCase @@ -262,6 +261,7 @@ class TestTrialUnittest: # will crash both at test time and at teardown """) result = testdir.runpytest() + assert 0 def test_trial_pdb(self, testdir): p = testdir.makepyfile(""" @@ -275,6 +275,46 @@ class TestTrialUnittest: child.expect("hellopdb") child.sendeof() + def test_trial_setup_failure_is_shown(self, testdir): + testdir.makepyfile(""" + from twisted.trial import unittest + import pytest + class TC(unittest.TestCase): + def setUp(self): + assert 0, "down1" + def test_method(self): + print ("never42") + xyz + """) + result = testdir.runpytest("-s") + assert result.ret == 1 + result.stdout.fnmatch_lines([ + "*setUp*", + "*assert 0*down1*", + "*1 failed*", + ]) + assert 'never42' not in result.stdout.str() + + def test_trial_teardown_and_test_failure(self, testdir): + testdir.makepyfile(""" + from twisted.trial import unittest + import pytest + class TC(unittest.TestCase): + def tearDown(self): + assert 0, "down1" + def test_method(self): + assert False, "down2" + """) + result = testdir.runpytest("-s") + assert result.ret == 1 + result.stdout.fnmatch_lines([ + "*tearDown*", + "*assert 0*", + "*test_method*", + "*assert False*", + "*1 failed*1 error*", + ]) + def test_djangolike_testcase(testdir): # contributed from Morten Breekevold testdir.makepyfile(""" _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn