0

我在使用 eclipse、pydev、nose 测试运行器和记录 unicode 文本时遇到了一个奇怪的问题。我不知道这是否只发生在我的配置和安装的版本中。所以,如果你们中的一些人可以尝试重现这个问题,并告诉我你是否有同样的问题,这对我很有帮助。我希望在下面的评论中复制所需的所有信息。请注意使用鼻子测试运行器,而不是禁用日志捕获。

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)。

4

1 回答 1

1

请注意,这确实是 PyDev 端通信中的一个问题(因此,尽管它显示了该错误,但它不应该真的使您的测试失败)。

我正在为 PyDev 建立一个新的跟踪器,作为http://igg.me/at/liclipse的一部分,所以请在跟踪器启动后将其报告为跟踪器中的错误。

于 2013-04-19T16:36:12.480 回答