summaryrefslogtreecommitdiff
path: root/dev-libs/libportal/files/6cd7c2ab82575b76f876ee2bd2d31f6cb77f022f.patch
blob: ea055c832dc8e3caeff8a45258e050d4cf48fe03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From 6cd7c2ab82575b76f876ee2bd2d31f6cb77f022f Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Tue, 26 Dec 2023 14:35:46 +0000
Subject: [PATCH] pyportaltest: Only create one session bus per DBusTestCase
 subclass

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: https://github.com/flatpak/libportal/issues/136
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1058245
Signed-off-by: Simon McVittie <smcv@debian.org>
---
 tests/pyportaltest/__init__.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/pyportaltest/__init__.py b/tests/pyportaltest/__init__.py
index af053c2a..80f04a91 100644
--- a/tests/pyportaltest/__init__.py
+++ b/tests/pyportaltest/__init__.py
@@ -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
@@ -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,