Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize D-Bus requirements for tests #5265

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ jobs:
- name: Install additional system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libpulse0 libudev1 dbus dbus-x11
sudo apt-get install -y --no-install-recommends libpulse0 libudev1 dbus-daemon
- name: Register Python problem matcher
run: |
echo "::add-matcher::.github/workflows/matchers/python.json"
Expand Down
35 changes: 22 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Common test functions."""

import asyncio
from collections.abc import AsyncGenerator, Generator
from functools import partial
from inspect import unwrap
import os
Expand Down Expand Up @@ -115,20 +116,28 @@ async def docker() -> DockerAPI:


@pytest.fixture(scope="session")
def dbus_session() -> None:
"""Start a dbus session."""
dbus_launch = subprocess.run(["dbus-launch"], stdout=subprocess.PIPE, check=False)
envs = dbus_launch.stdout.decode(encoding="utf-8").rstrip()

for env in envs.split("\n"):
name, value = env.split("=", 1)
os.environ[name] = value


@pytest.fixture
async def dbus_session_bus(dbus_session) -> MessageBus:
def dbus_session() -> Generator[str, None, None]:
"""Start a dbus session.

Returns session address.
"""
with subprocess.Popen(
[
"dbus-daemon",
"--nofork",
"--print-address",
"--session",
],
stdout=subprocess.PIPE,
) as proc:
yield proc.stdout.readline().decode("utf-8").strip()
proc.terminate()


@pytest.fixture
async def dbus_session_bus(dbus_session) -> AsyncGenerator[MessageBus, None, None]:
"""Return message bus connected to session dbus."""
bus = await MessageBus(bus_type=BusType.SESSION).connect()
bus = await MessageBus(bus_type=BusType.SESSION, bus_address=dbus_session).connect()
yield bus
bus.disconnect()

Expand Down
Loading