From 41d019aa495fce0dee8a6b1ebe5140c83adc1c39 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 3 Nov 2023 15:42:22 +1000 Subject: [PATCH] tests/conftest: Don't subclass dbusmock.DBusTestCase For historical reasons, dbusmock is written for Python's unittest framework and most of what it does is done via @classmethod. We called it on the subclassed object though, so we got some weird behaviors. In particular, things like `a = foo.someval` would resolve to the parent class' `someval` but `foo.someval = a` would set that value on the subclassed object. This lead, indirectly, to our forked dbus-daemon not getting terminated. This needs to be be fixed in dbusmock (see [1]) but for now simply work around this by instantiating the DBusTestCase class directly. [1] https://github.com/martinpitt/python-dbusmock/pull/184 --- tests/conftest.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fac8c7853..5a2f738c0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,27 +11,17 @@ from tests import PortalMock -class SessionBusMock(dbusmock.DBusTestCase): - def __init__(self): - super().__init__() - self._dbus_con = None - - @property - def dbus_con(self) -> "dbus.Bus": - return self._dbus_con - - @pytest.fixture() -def session_bus() -> Iterator[SessionBusMock]: +def session_bus() -> Iterator[dbusmock.DBusTestCase]: """ Fixture to yield a DBusTestCase with a started session bus. """ - bus = SessionBusMock() + bus = dbusmock.DBusTestCase() bus.setUp() bus.start_session_bus() con = bus.get_dbus(system_bus=False) assert con - bus._dbus_con = con + setattr(bus, "dbus_con", con) yield bus bus.tearDown() bus.tearDownClass()