summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2021-08-25 15:22:42 +0200
committerBenjamin Berg <bberg@redhat.com>2021-08-25 15:22:42 +0200
commit717a9199963d1ea8c96f9208ecdca18a12247481 (patch)
tree0f972c58993477c85d331e989345afd7b9d2c025
parente6fc854a9ae3f640945ff621959cf9984e7d036a (diff)
tests: Make class cleanup more robust
Use addClassCleanup rather than doing cleanup in tearDownClass, which may not be called in all cases.
-rw-r--r--tests/fprintd.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/tests/fprintd.py b/tests/fprintd.py
index 0dea501..7d9eb4d 100644
--- a/tests/fprintd.py
+++ b/tests/fprintd.py
@@ -201,6 +201,7 @@ class FPrintdTest(dbusmock.DBusTestCase):
cls.tmpdir = tempfile.mkdtemp(prefix='libfprint-')
+ cls.addClassCleanup(shutil.rmtree, cls.tmpdir)
cls.sockaddr = os.path.join(cls.tmpdir, 'virtual-image.socket')
os.environ[cls.socket_env] = cls.sockaddr
@@ -213,6 +214,7 @@ class FPrintdTest(dbusmock.DBusTestCase):
cls.test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
cls.test_bus.up()
+ cls.addClassCleanup(cls.test_bus.down)
cls.test_bus.unset()
addr = cls.test_bus.get_bus_address()
os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = addr
@@ -220,16 +222,14 @@ class FPrintdTest(dbusmock.DBusTestCase):
Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION |
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, None, None)
assert cls.dbus.is_closed() == False
+ cls.addClassCleanup(cls.dbus.close)
@classmethod
def tearDownClass(cls):
- cls.dbus.close()
- cls.test_bus.down()
- del cls.dbus
- del cls.test_bus
- shutil.rmtree(cls.tmpdir)
dbusmock.DBusTestCase.tearDownClass()
+ del cls.dbus
+ del cls.test_bus
def daemon_start(self, driver='Virtual image device for debugging'):
timeout = get_timeout('daemon_start') # seconds