Fix cleanup of symlink fixtures

These aren't all getting cleaned up, which winds up breaking
the second runs. Instead of doing addCleanup with a method that
does the loop again, which can fail in the middle and not
clean up subsequent files, add an individual cleanup when we
add the symlink. This results in all of the symlinks consistently
being cleaned.

Change-Id: Id5a5b09c830ad2ad3bb0b77fb9dbdc494c629824
This commit is contained in:
Monty Taylor 2020-02-22 10:53:04 -06:00
parent 2e33459b3e
commit 635be2a3ae
4 changed files with 4 additions and 32 deletions

View File

@ -43,17 +43,10 @@ class SymlinkFixture(fixtures.Fixture):
] ]
def _setUp(self): def _setUp(self):
self._cleanup()
for (src, target) in self.links: for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src) path = os.path.join(FIXTURE_DIR, 'links', src)
os.symlink(target, path) os.symlink(target, path)
self.addCleanup(self._cleanup) self.addCleanup(os.unlink, path)
def _cleanup(self):
for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src)
if os.path.exists(path):
os.unlink(path)
class TestFileList(testtools.TestCase): class TestFileList(testtools.TestCase):

View File

@ -44,17 +44,10 @@ class SymlinkFixture(fixtures.Fixture):
] ]
def _setUp(self): def _setUp(self):
self._cleanup()
for (src, target) in self.links: for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src) path = os.path.join(FIXTURE_DIR, 'links', src)
os.symlink(target, path) os.symlink(target, path)
self.addCleanup(self._cleanup) self.addCleanup(os.unlink, path)
def _cleanup(self):
for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src)
if os.path.exists(path):
os.unlink(path)
class TestFileList(testtools.TestCase): class TestFileList(testtools.TestCase):

View File

@ -44,17 +44,10 @@ class SymlinkFixture(fixtures.Fixture):
] ]
def _setUp(self): def _setUp(self):
self._cleanup()
for (src, target) in self.links: for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src) path = os.path.join(FIXTURE_DIR, 'links', src)
os.symlink(target, path) os.symlink(target, path)
self.addCleanup(self._cleanup) self.addCleanup(os.unlink, path)
def _cleanup(self):
for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src)
if os.path.exists(path):
os.unlink(path)
class TestFileList(testtools.TestCase): class TestFileList(testtools.TestCase):

View File

@ -44,17 +44,10 @@ class SymlinkFixture(fixtures.Fixture):
] ]
def _setUp(self): def _setUp(self):
self._cleanup()
for (src, target) in self.links: for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src) path = os.path.join(FIXTURE_DIR, 'links', src)
os.symlink(target, path) os.symlink(target, path)
self.addCleanup(self._cleanup) self.addCleanup(os.unlink, path)
def _cleanup(self):
for (src, target) in self.links:
path = os.path.join(FIXTURE_DIR, 'links', src)
if os.path.exists(path):
os.unlink(path)
class TestFileList(testtools.TestCase): class TestFileList(testtools.TestCase):