Rev 4800: Add a details object to bzr tests containing the test log. May currently result in failures show the log twice (but will now show the log in --subunit mode [which includes --parallel]). in http://bazaar.launchpad.net/~lifeless/bzr/subunit
Robert Collins
robertc at robertcollins.net
Sat Dec 5 09:32:08 GMT 2009
At http://bazaar.launchpad.net/~lifeless/bzr/subunit
------------------------------------------------------------
revno: 4800
revision-id: robertc at robertcollins.net-20091205093203-ag0ns6opjo27tvv0
parent: robertc at robertcollins.net-20091205090419-emezfnmspowra66n
committer: Robert Collins <robertc at robertcollins.net>
branch nick: subunit
timestamp: Sat 2009-12-05 20:32:03 +1100
message:
Add a details object to bzr tests containing the test log. May currently result in failures show the log twice (but will now show the log in --subunit mode [which includes --parallel]).
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-12-05 08:44:50 +0000
+++ b/bzrlib/tests/__init__.py 2009-12-05 09:32:03 +0000
@@ -50,6 +50,7 @@
import warnings
import testtools
+from testtools import content
from bzrlib import (
branchbuilder,
@@ -783,7 +784,6 @@
_leaking_threads_tests = 0
_first_thread_leaker_id = None
_log_file_name = None
- _log_contents = ''
_keep_log_file = False
# record lsprof data when performing benchmark calls.
_gather_lsprof_in_benchmarks = False
@@ -798,6 +798,10 @@
(TestNotApplicable, self._do_not_applicable))
self.exception_handlers.insert(0,
(KnownFailure, self._do_known_failure))
+ self._log_contents = ''
+ self.addDetail("log", content.Content(content.ContentType("text",
+ "plain", {"charset": "utf8"}),
+ lambda:[self._get_log(keep_log_file=True)]))
def setUp(self):
super(TestCase, self).setUp()
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2009-12-05 08:35:55 +0000
+++ b/bzrlib/tests/test_selftest.py 2009-12-05 09:32:03 +0000
@@ -17,6 +17,7 @@
"""Tests for the test framework."""
from cStringIO import StringIO
+from doctest import ELLIPSIS
import os
import signal
import sys
@@ -24,8 +25,13 @@
import unittest
import warnings
+from testtools import MultiTestResult
+from testtools.content_type import ContentType
+from testtools.matchers import (
+ DocTestMatches,
+ Equals,
+ )
import testtools.tests.helpers
-from testtools import MultiTestResult
import bzrlib
from bzrlib import (
@@ -81,14 +87,18 @@
TestUtil._load_module_by_name,
'bzrlib.no-name-yet')
+
class MetaTestLog(tests.TestCase):
def test_logging(self):
"""Test logs are captured when a test fails."""
self.log('a test message')
- self._log_file.flush()
- self.assertContainsRe(self._get_log(keep_log_file=True),
- 'a test message\n')
+ details = self.getDetails()
+ log = details['log']
+ self.assertThat(log.content_type, Equals(ContentType(
+ "text", "plain", {"charset": "utf8"})))
+ self.assertThat(u"".join(log.iter_text()),
+ DocTestMatches(u"...a test message\n", ELLIPSIS))
class TestUnicodeFilename(tests.TestCase):
More information about the bazaar-commits
mailing list