diff --git a/unittests/baseplatformtests.py b/unittests/baseplatformtests.py index ae012dada..0886e5190 100644 --- a/unittests/baseplatformtests.py +++ b/unittests/baseplatformtests.py @@ -91,7 +91,6 @@ class BasePlatformTests(TestCase): os.environ['COLUMNS'] = '80' os.environ['PYTHONIOENCODING'] = 'utf8' - self.builddirs = [] self.new_builddir() def change_builddir(self, newdir): @@ -101,7 +100,10 @@ class BasePlatformTests(TestCase): self.installdir = os.path.join(self.builddir, 'install') self.distdir = os.path.join(self.builddir, 'meson-dist') 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): # Keep builddirs inside the source tree so that virus scanners @@ -141,14 +143,6 @@ class BasePlatformTests(TestCase): if 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): ''' Run a command while printing the stdout and stderr to stdout, diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index cfad8fece..97602236d 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -281,7 +281,6 @@ class LinuxlikeTests(BasePlatformTests): symdir = f'{self.builddir}-symlink' os.symlink(self.builddir, symdir) - self.addCleanup(os.unlink, symdir) self.change_builddir(symdir) self.init(testdir)