diff options
author | Prabhu Ramachandran <prabhu@aero.iitb.ac.in> | 2015-08-27 01:39:16 +0530 |
---|---|---|
committer | Prabhu Ramachandran <prabhu@aero.iitb.ac.in> | 2015-08-27 01:39:16 +0530 |
commit | 14cbbc3f6d282d9c48bb3d6aa8c048be124780ab (patch) | |
tree | 619150a12ec5dfbded839db6fabd39c2f56a6a2f | |
parent | 716d822d43db30195f795daa9fd71d54e682ec0c (diff) | |
download | nose-14cbbc3f6d282d9c48bb3d6aa8c048be124780ab.tar.gz |
BUG: Tee doesn't have encoding or errors attrs.
On Python3, distutils.log uses the encoding and errors attribute of
sys.stdout and stderr. Tests error out when nose is run with xunit and
it replaces the stdout/stderr with a Tee.
-rw-r--r-- | nose/plugins/xunit.py | 5 | ||||
-rw-r--r-- | unit_tests/test_xunit.py | 25 |
2 files changed, 24 insertions, 6 deletions
diff --git a/nose/plugins/xunit.py b/nose/plugins/xunit.py index 90b52f5..b43ff04 100644 --- a/nose/plugins/xunit.py +++ b/nose/plugins/xunit.py @@ -120,11 +120,12 @@ def exc_message(exc_info): class Tee(object): def __init__(self, encoding, *args): - self._encoding = encoding + self.encoding = encoding self._streams = args + self.errors = None def write(self, data): - data = force_unicode(data, self._encoding) + data = force_unicode(data, self.encoding) for s in self._streams: s.write(data) diff --git a/unit_tests/test_xunit.py b/unit_tests/test_xunit.py index d98ccba..ba839e1 100644 --- a/unit_tests/test_xunit.py +++ b/unit_tests/test_xunit.py @@ -8,7 +8,7 @@ from xml.sax import saxutils from nose.pyversion import UNICODE_STRINGS from nose.tools import eq_ -from nose.plugins.xunit import Xunit, escape_cdata, id_split +from nose.plugins.xunit import Xunit, escape_cdata, id_split, Tee from nose.exc import SkipTest from nose.config import Config @@ -67,11 +67,29 @@ class TestOptions(unittest.TestCase): (options, args) = parser.parse_args(["--xunit-file=blagojevich.xml"]) eq_(options.xunit_file, "blagojevich.xml") +class TestTee(unittest.TestCase): + def setUp(self): + self.orig_stderr = sys.stderr + sys.stderr = Tee('utf-8', self.orig_stderr) + + def tearDown(self): + sys.stderr = self.orig_stderr + + def test_tee_has_error_and_encoding_attributes(self): + tee = Tee('utf-8', sys.stdout) + self.assertTrue(hasattr(tee, 'encoding')) + self.assertTrue(hasattr(tee, 'errors')) + + def test_tee_works_with_distutils_log(self): + from distutils.log import Log, DEBUG + l = Log(DEBUG) + l.warn('Test') + class TestXMLOutputWithXML(unittest.TestCase): def setUp(self): self.xmlfile = os.path.abspath( - os.path.join(os.path.dirname(__file__), + os.path.join(os.path.dirname(__file__), 'support', 'xunit.xml')) parser = optparse.OptionParser() self.x = Xunit() @@ -215,7 +233,7 @@ class TestXMLOutputWithXML(unittest.TestCase): test = mktest() self.x.beforeTest(test) try: - raise RuntimeError(chr(128)) # cannot encode as utf8 + raise RuntimeError(chr(128)) # cannot encode as utf8 except RuntimeError: some_err = sys.exc_info() self.x.addError(test, some_err) @@ -309,4 +327,3 @@ class TestXMLOutputWithXML(unittest.TestCase): assert '<?xml version="1.0" encoding="UTF-8"?>' in result assert ('<testcase classname="test_xunit.TC" ' 'name="runTest" time="0') in result - |