Skip to content

Commit

Permalink
tests/conftest: Don't subclass dbusmock.DBusTestCase
Browse files Browse the repository at this point in the history
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] martinpitt/python-dbusmock#184
  • Loading branch information
whot committed Nov 6, 2023
1 parent 127cfdd commit f9c33f2
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f9c33f2

Please sign in to comment.