class AutoreloadTest(unittest.TestCase):
+ def setUp(self):
+ self.path = mkdtemp()
+
+ def tearDown(self):
+ try:
+ shutil.rmtree(self.path)
+ except OSError:
+ # Windows disallows deleting files that are in use by
+ # another process, and even though we've waited for our
+ # child process below, it appears that its lock on these
+ # files is not guaranteed to be released by this point.
+ # Sleep and try again (once).
+ time.sleep(1)
+ shutil.rmtree(self.path)
def test_reload_module(self):
main = """\
"""
# Create temporary test application
- path = mkdtemp()
- self.addCleanup(shutil.rmtree, path)
- os.mkdir(os.path.join(path, 'testapp'))
- open(os.path.join(path, 'testapp/__init__.py'), 'w').close()
- with open(os.path.join(path, 'testapp/__main__.py'), 'w') as f:
+ os.mkdir(os.path.join(self.path, 'testapp'))
+ open(os.path.join(self.path, 'testapp/__init__.py'), 'w').close()
+ with open(os.path.join(self.path, 'testapp/__main__.py'), 'w') as f:
f.write(main)
# Make sure the tornado module under test is available to the test
p = Popen(
[sys.executable, '-m', 'testapp'], stdout=subprocess.PIPE,
- cwd=path, env=dict(os.environ, PYTHONPATH=pythonpath),
+ cwd=self.path, env=dict(os.environ, PYTHONPATH=pythonpath),
universal_newlines=True)
out = p.communicate()[0]
self.assertEqual(out, 'Starting\nStarting\n')
"""
# Create temporary test application
- path = mkdtemp()
- os.mkdir(os.path.join(path, 'testapp'))
- self.addCleanup(shutil.rmtree, path)
- init_file = os.path.join(path, 'testapp', '__init__.py')
+ os.mkdir(os.path.join(self.path, 'testapp'))
+ init_file = os.path.join(self.path, 'testapp', '__init__.py')
open(init_file, 'w').close()
- main_file = os.path.join(path, 'testapp', '__main__.py')
+ main_file = os.path.join(self.path, 'testapp', '__main__.py')
with open(main_file, 'w') as f:
f.write(main)
autoreload_proc = Popen(
[sys.executable, '-m', 'tornado.autoreload', '-m', 'testapp'],
- stdout=subprocess.PIPE, cwd=path,
+ stdout=subprocess.PIPE, cwd=self.path,
env=dict(os.environ, PYTHONPATH=pythonpath),
universal_newlines=True)