Tests: ensure temporary directories and files are removed after tests

- QSettings object needs special care, as file was re-created on exit
- Append a cleanup function as soon as possible to ensure temporary dirs & files are removed in any case
- prefer addCleanup() over tearDown(), keeping creation and cleanup together
This commit is contained in:
Laurent Monin
2020-02-08 16:19:30 +01:00
parent b7281c5147
commit b7389a6445
8 changed files with 74 additions and 72 deletions

View File

@@ -43,13 +43,11 @@ class TestPreserveTimes(PicardTestCase):
def setUp(self):
super().setUp()
self.tmp_directory = mkdtemp()
self.tmp_directory = mkdtemp(suffix=self.__class__.__name__)
self.addCleanup(shutil.rmtree, self.tmp_directory)
filepath = os.path.join(self.tmp_directory, 'a.mp3')
self.file = File(filepath)
def tearDown(self):
shutil.rmtree(self.tmp_directory)
def _create_testfile(self):
# create a dummy file
with open(self.file.filename, 'w') as f: