From e0ab7290f0c75e485876c24a795925ae8462a1ce Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 19 Aug 2021 09:17:57 -0700 Subject: [PATCH] unittests: Ensure that symlink is removed after tests complete using `TestCase.addCleanup` is both neat and tidy, and also ensures that the cleanup will be done, even if the test fails. --- unittests/linuxliketests.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index a86c3dc1e..2bcf5c933 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -264,14 +264,18 @@ class LinuxlikeTests(BasePlatformTests): pcfile = f.read() self.assertFalse('blub_blob_blib' in pcfile) - def test_symlink_builddir(self): + def test_symlink_builddir(self) -> None: ''' Test using a symlink as either the builddir for "setup" or the argument for "-C". ''' testdir = os.path.join(self.common_test_dir, '1 trivial') - os.symlink(self.builddir, self.builddir + '-symlink') - self.change_builddir(self.builddir + '-symlink') + + symdir = f'{self.builddir}-symlink' + os.symlink(self.builddir, symdir) + self.addCleanup(os.unlink, symdir) + self.change_builddir(symdir) + self.init(testdir) self.build() self._run(self.mtest_command)