pydev,nose test runner和unicode组合在xmlrpclib中引发意外异常

时间:2013-04-19 09:41:06

标签: python unicode pydev nose

我有一个奇怪的问题,使用eclipse,pydev,nose test runner和记录unicode文本。我不知道这是否只发生在我的配置和版本中。所以,如果你们中的一些人可以尝试重现这个问题,并告诉我你是否有同样的问题,那对我来说会很有帮助。我希望在下面的评论中重现所需的所有信息。 请注意使用nose test runner和 not 来禁用日志捕获。

import unittest
import logging

class WeirdUnicodeTestProblem(unittest.TestCase):
    """
    Weird Exception is raised in
        xmlrpclib (!)
    Fault: <Fault 0: 'Failed to read XML-RPC request:
        Invalid byte 1 of 1-byte UTF-8 sequence.'>
    Occurs when this is true:
     - nose test runner with log capturing on (=default)
     - eclipse + pydev
     - log some unicode text containing non standard ascii characters
     - raise any exception after logging 
    It does NOT occur when using nosetests on the commandline.
    """
    def test_problem(self):
        """
        This is how the problem can be reproduced
        """
        logger = logging.getLogger('bla')
        logger.debug(u'internation\xe4l')
        self.assertEqual(1, 2) # any exception raised will do here

    #def test_OK(self):
    #    """
    #    This is how the problem does not occur
    #    """
    #    logger = logging.getLogger('bla')
    #    logger.debug(u'good old 7bit')
    #    self.assertEqual(1, 2) # any exception raised will do here

这是追溯:

Traceback (most recent call last):
  File "/Applications/eclipse_4.2.1/plugins/org.python.pydev_2.7.3.2013031601/pysrc/pydev_runfiles_xml_rpc.py", line 131, in run
    self.server.notifyCommands(commands)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1575, in __request
    verbose=self.__verbose
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
Fault: <Fault 0: 'Failed to read XML-RPC request: Invalid byte 1 of 1-byte UTF-8 sequence.'>

有一件事情更奇怪:如果我在第131行的pydev_runfiles_xml_rpc.py设置断点并尝试调试它,断点甚至没有被击中,但代码运行得很干净(按预期引发AssertionError)。

1 个答案:

答案 0 :(得分:0)

请注意,这在PyDev方面的通信中确实存在问题(因此,虽然它显示错误,但它不应该让您的测试失败)。

我正在为PyDev添加一个新的跟踪器作为http://igg.me/at/liclipse的一部分,因此,请将其报告为跟踪器中的错误。