# HG changeset patch # User Gregory Szorc # Date 1398042938 25200 # Node ID 798c81e32b5ebc4598d6468bee6adeb4e0b7cd3d # Parent f145914e698d8626936ddf28cfa006965bd81f95 run-tests: refactor temporary directories in Test We no longer need cleanup() because setUp() and tearDown() cover it. We move tempdir creation into setUp() and always delete in tearDown() diff -r f145914e698d -r 798c81e32b5e tests/run-tests.py --- a/tests/run-tests.py Sun Apr 20 17:42:31 2014 -0700 +++ b/tests/run-tests.py Sun Apr 20 18:15:38 2014 -0700 @@ -330,8 +330,9 @@ class Test(unittest.TestCase): """Encapsulates a single, runnable test. - Test instances can be run multiple times via run(). However, multiple - runs cannot be run concurrently. + While this class conforms to the unittest.TestCase API, it differs in that + instances need to be instantiated manually. (Typically, unittest.TestCase + classes are instantiated automatically by scanning modules.) """ # Status code reserved for skipped tests (used by hghave). @@ -370,16 +371,6 @@ self._refout = [] self._threadtmp = os.path.join(runner.hgtmp, 'child%d' % count) - os.mkdir(self._threadtmp) - - def cleanup(self): - for entry in self._daemonpids: - killdaemons(entry) - - if self._threadtmp and not self._options.keep_tmpdir: - # Ignore failures here. The rmtree() in the higher level runner - # will try again. - shutil.rmtree(self._threadtmp, True) def __str__(self): return self.name @@ -394,6 +385,12 @@ self._out = None self._skipped = None + try: + os.mkdir(self._threadtmp) + except OSError, e: + if e.errno != errno.EEXIST: + raise + self._testtmp = os.path.join(self._threadtmp, os.path.basename(self._path)) os.mkdir(self._testtmp) @@ -560,6 +557,7 @@ if not self._options.keep_tmpdir: shutil.rmtree(self._testtmp, True) + shutil.rmtree(self._threadtmp, True) if (self._ret != 0 or self._out != self._refout) and not self._skipped \ and not self._options.debug and self._out: