Skip to content

Commit

Permalink
pyportaltest: Only create one session bus per DBusTestCase subclass
Browse files Browse the repository at this point in the history
DBusTestCase.start_session_bus() is a class method, and can only be
called once per class, because DBusTestCase.tearDownClass() will only
clean up one session bus. In older versions of dbusmock, calling it more
than once will result in dbus-daemon processes being leaked; since
0.30.0, calling it more than once will result in an assertion failure.

Resolves: flatpak#136
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1058245
Signed-off-by: Simon McVittie <smcv@debian.org>
  • Loading branch information
smcv committed Dec 26, 2023
1 parent f15ea50 commit 7ce8835
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/pyportaltest/__init__.py
Expand Up @@ -83,6 +83,14 @@ def setUpClass(cls):
except AttributeError:
pytest.skip("Updated version of dbusmock required")

cls.__have_session_bus = False

@classmethod
def ensure_session_bus(cls):
if not cls.__have_session_bus:
cls.__have_session_bus = True
cls.start_session_bus()

def setUp(self):
self.p_mock = None
self._mainloop = None
Expand All @@ -96,7 +104,7 @@ def setup_daemon(self, params=None, extra_templates: List[Tuple[str, Dict]] = []
portal name as first value and the param dict to be passed to that
template as second value, e.g. ("ScreenCast", {...}).
"""
self.start_session_bus()
self.ensure_session_bus()
self.p_mock, self.obj_portal = self.spawn_server_template(
template=f"pyportaltest/templates/{self.PORTAL_NAME.lower()}.py",
parameters=params,
Expand Down

0 comments on commit 7ce8835

Please sign in to comment.