Python 运行Tornado AsyncHTTPTestCase时获取错误的文件描述符

Python 运行Tornado AsyncHTTPTestCase时获取错误的文件描述符,python,unit-testing,tornado,Python,Unit Testing,Tornado,当使用Tornado AsyncHTTPTestCase运行测试时,我得到的堆栈跟踪与测试无关。测试通过了,所以这可能是在测试清理时发生的 我正在使用Python 2.7.2和Tornado 2.2 测试代码为: class AllServersHandlerTest(AsyncHTTPTestCase): def get_app(self): return Application([('/rest/test/', AllServersHandler)]) d

当使用Tornado AsyncHTTPTestCase运行测试时,我得到的堆栈跟踪与测试无关。测试通过了,所以这可能是在测试清理时发生的

我正在使用Python 2.7.2和Tornado 2.2

测试代码为:

class AllServersHandlerTest(AsyncHTTPTestCase):

    def get_app(self):
        return Application([('/rest/test/', AllServersHandler)])

    def test_server_status_with_advertiser(self):
        on_new_host(None, '127.0.0.1')
        response = self.fetch('/rest/test/', method='GET')
        result = json.loads(response.body, 'utf8').get('data')
        self.assertEquals(['127.0.0.1'], result)
测试通过了,但我从Tornado服务器获得了以下堆栈跟踪

OSError: [Errno 9] Bad file descriptor
INFO:root:200 POST /rest/serverStatuses (127.0.0.1) 0.00ms
DEBUG:root:error closing fd 688
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\tornado-2.2-py2.7.egg\tornado\ioloop.py", line 173, in close
    os.close(fd)
OSError: [Errno 9] Bad file descriptor

你知道如何彻底关闭测试用例吗?

我仔细查看了tornado代码,发现该代码正在将all_fds设置为True,从而导致io_循环中的堆栈跟踪。close():

因此,重写测试类中的tearDown()会停止堆栈跟踪

class AllServersHandlerTest(AsyncHTTPTestCase):

    def tearDown(self):
        pass

    def get_app(self):
        return Application([('/rest/test/', AllServersHandler)])

    def test_server_status_with_advertiser(self):
        on_new_host(None, '127.0.0.1')
        response = self.fetch('/rest/test/', method='GET')
        result = json.loads(response.body, 'utf8').get('data')
        self.assertEquals(['127.0.0.1'], result)
我不确定这种方法会带来什么损害,所以如果其他人有更好的建议,请告诉我

class AllServersHandlerTest(AsyncHTTPTestCase):

    def tearDown(self):
        pass

    def get_app(self):
        return Application([('/rest/test/', AllServersHandler)])

    def test_server_status_with_advertiser(self):
        on_new_host(None, '127.0.0.1')
        response = self.fetch('/rest/test/', method='GET')
        result = json.loads(response.body, 'utf8').get('data')
        self.assertEquals(['127.0.0.1'], result)