From 06480c7994d7ad5258b3a4c7e5fb33d529f8289b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 7 Feb 2020 17:44:46 +0100 Subject: [PATCH] tests/fprintd: Use a new bus for each test unit When creating a new unit we used to get the system bus via Gio.bus_get_sync, however this has a singleton implementation, and so would always return the same connection, creating issues in tests when a new test suite is added because the newly got connection would be already closed. So, just manually create a new bus connection, also close the bus and cleanup the test bus in dbus. --- tests/fprintd.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/fprintd.py b/tests/fprintd.py index e5a20af..8f35b24 100755 --- a/tests/fprintd.py +++ b/tests/fprintd.py @@ -1,5 +1,6 @@ #! /usr/bin/env python3 # Copyright © 2017, 2019 Red Hat, Inc +# Copyright © 2020 Canonical Ltd # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -157,12 +158,19 @@ class FPrintdTest(dbusmock.DBusTestCase): del os.environ['DBUS_SESSION_BUS_ADDRESS'] except KeyError: pass - os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = cls.test_bus.get_bus_address() - cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) + addr = cls.test_bus.get_bus_address() + os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = addr + cls.dbus = Gio.DBusConnection.new_for_address_sync(addr, + Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION | + Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, None, None) + assert cls.dbus.is_closed() == False @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()