From b8d0742b557813b1e5334d47be7ef336c5932661 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Mon, 27 Aug 2012 17:45:50 -0400 Subject: [PATCH] Run twisted tests in a temporary directory so they don't leak temp files. This mainly affected the unix socket tests. --- tornado/test/twisted_test.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tornado/test/twisted_test.py b/tornado/test/twisted_test.py index 2ebbb8945..cd7fc60d9 100644 --- a/tornado/test/twisted_test.py +++ b/tornado/test/twisted_test.py @@ -20,7 +20,9 @@ Unittest for the twisted-style reactor. from __future__ import absolute_import, division, with_statement import os +import shutil import signal +import tempfile import thread import threading import unittest @@ -452,8 +454,6 @@ else: 'twisted.internet.test.test_process.ProcessTestsBuilder': [ # Doesn't work on python 2.5 'test_systemCallUninterruptedByChildExit', - # Doesn't clean up its temp files - 'test_shebang', ], # Process tests appear to work on OSX 10.7, but not 10.6 #'twisted.internet.test.test_process.PTYProcessTestsBuilder': [ @@ -510,6 +510,20 @@ else: class TornadoTest(test_class): _reactors = ["tornado.platform.twisted._TestReactor"] + def setUp(self): + # Twisted's tests expect to be run from a temporary + # directory; they create files in their working directory + # and don't always clean up after themselves. + self.__curdir = os.getcwd() + self.__tempdir = tempfile.mkdtemp() + os.chdir(self.__tempdir) + super(TornadoTest, self).setUp() + + def tearDown(self): + super(TornadoTest, self).tearDown() + os.chdir(self.__curdir) + shutil.rmtree(self.__tempdir) + def buildReactor(self): self.__saved_signals = save_signal_handlers() return test_class.buildReactor(self) -- 2.47.2