unittests: use TestCase.addCleanup for cleaning up builddirs

pull/13552/head
Dylan Baker 4 months ago committed by Eli Schwartz
parent 5eb4d7336b
commit e808aa161c
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 14
      unittests/baseplatformtests.py
  2. 1
      unittests/linuxliketests.py

@ -91,7 +91,6 @@ class BasePlatformTests(TestCase):
os.environ['COLUMNS'] = '80' os.environ['COLUMNS'] = '80'
os.environ['PYTHONIOENCODING'] = 'utf8' os.environ['PYTHONIOENCODING'] = 'utf8'
self.builddirs = []
self.new_builddir() self.new_builddir()
def change_builddir(self, newdir): def change_builddir(self, newdir):
@ -101,7 +100,10 @@ class BasePlatformTests(TestCase):
self.installdir = os.path.join(self.builddir, 'install') self.installdir = os.path.join(self.builddir, 'install')
self.distdir = os.path.join(self.builddir, 'meson-dist') self.distdir = os.path.join(self.builddir, 'meson-dist')
self.mtest_command = self.meson_command + ['test', '-C', self.builddir] self.mtest_command = self.meson_command + ['test', '-C', self.builddir]
self.builddirs.append(self.builddir) if os.path.islink(newdir):
self.addCleanup(os.unlink, self.builddir)
else:
self.addCleanup(windows_proof_rmtree, self.builddir)
def new_builddir(self): def new_builddir(self):
# Keep builddirs inside the source tree so that virus scanners # Keep builddirs inside the source tree so that virus scanners
@ -141,14 +143,6 @@ class BasePlatformTests(TestCase):
if log: if log:
print(log) print(log)
def tearDown(self):
for path in self.builddirs:
try:
windows_proof_rmtree(path)
except FileNotFoundError:
pass
super().tearDown()
def _run(self, command, *, workdir=None, override_envvars: T.Optional[T.Mapping[str, str]] = None, stderr=True): def _run(self, command, *, workdir=None, override_envvars: T.Optional[T.Mapping[str, str]] = None, stderr=True):
''' '''
Run a command while printing the stdout and stderr to stdout, Run a command while printing the stdout and stderr to stdout,

@ -281,7 +281,6 @@ class LinuxlikeTests(BasePlatformTests):
symdir = f'{self.builddir}-symlink' symdir = f'{self.builddir}-symlink'
os.symlink(self.builddir, symdir) os.symlink(self.builddir, symdir)
self.addCleanup(os.unlink, symdir)
self.change_builddir(symdir) self.change_builddir(symdir)
self.init(testdir) self.init(testdir)

Loading…
Cancel
Save