Mercurial > hg
changeset 21497:798c81e32b5e
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()
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Apr 2014 18:15:38 -0700 |
parents | f145914e698d |
children | 6b8daeea638a |
files | tests/run-tests.py |
diffstat | 1 files changed, 10 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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: