Skip to content

Commit

Permalink
tests/py: Enable umockdev based tests
Browse files Browse the repository at this point in the history
We re-exec the test case in pytest_configure if the LD_PRELOAD doesn't
contain libumockdev-preload.so. Even if the system doesn't have it, it
will show up in the environment and we can continue.

It also sets the UMOCKDEV_DIR env for the portal frontend. In theory
dbusmock should already do this for us but it doesn't seem to be
working.
  • Loading branch information
swick committed Oct 17, 2024
1 parent 796f9f4 commit 5163404
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ def __init__(
self,
dbus_test_case,
portal_name: str,
app_id: str = "org.example.App"
app_id: str = "org.example.App",
umockdev = None,
):
self.dbus_test_case = dbus_test_case
self.portal_name = portal_name
Expand All @@ -346,6 +347,7 @@ def __init__(
self.portal_interfaces: Dict[str, dbus.Interface] = {}
self.app_id = app_id
self.busses = {dbusmock.BusType.SYSTEM: {}, dbusmock.BusType.SESSION: {}}
self.umockdev = umockdev

@property
def interface_name(self) -> str:
Expand Down Expand Up @@ -443,6 +445,9 @@ def start_xdp(self):
env["XDG_CURRENT_DESKTOP"] = "test"
env["XDG_DESKTOP_PORTAL_TEST_APP_ID"] = self.app_id

if self.umockdev:
env["UMOCKDEV_DIR"] = self.umockdev.get_root_dir()

self.start_dbus_monitor()
self.start_portal_frontend(env)
self.start_permission_store(env)
Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@
import pytest
import dbusmock
import os
import sys
import tempfile

from tests import PortalMock


def pytest_configure():
ensure_umockdev_loaded()
create_test_dirs()


def ensure_umockdev_loaded():
umockdev_preload = "libumockdev-preload.so"
preload = os.environ.get("LD_PRELOAD", "")
if umockdev_preload not in preload:
os.environ["LD_PRELOAD"] = f"{umockdev_preload}:{preload}"
os.execv(sys.executable, [sys.executable] + sys.argv)


def create_test_dirs():
test_root = tempfile.TemporaryDirectory(
prefix='xdp-testroot-',
Expand Down Expand Up @@ -124,13 +134,22 @@ def app_id():
return "org.example.App"


@pytest.fixture
def umockdev():
"""
Default fixture providing a umockdev testbed
"""
return None


@pytest.fixture
def portal_mock(
dbus_test_case,
portal_name,
required_templates,
template_params,
app_id,
umockdev,
) -> PortalMock:
"""
Fixture yielding a PortalMock object with the impl started, if applicable.
Expand All @@ -139,6 +158,7 @@ def portal_mock(
dbus_test_case,
portal_name,
app_id=app_id,
umockdev=umockdev,
)

for template, params in required_templates.items():
Expand Down

0 comments on commit 5163404

Please sign in to comment.