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

@@ -1,6 +1,5 @@
import os.path
import shutil
import sys
import tempfile
from test.picardtestcase import PicardTestCase
@@ -13,15 +12,10 @@ class Testbytes2human(PicardTestCase):
def setUp(self):
super().setUp()
# we are using temporary locales for tests
self.tmp_path = tempfile.mkdtemp()
if sys.hexversion >= 0x020700F0:
self.addCleanup(shutil.rmtree, self.tmp_path)
self.tmp_path = tempfile.mkdtemp(suffix=self.__class__.__name__)
self.addCleanup(shutil.rmtree, self.tmp_path)
self.localedir = os.path.join(self.tmp_path, 'locale')
def tearDown(self):
if sys.hexversion < 0x020700F0:
shutil.rmtree(self.tmp_path)
def test_00(self):
# testing with default C locale, english
lang = 'C'