TestDBus

Added in version 2.34.

class TestDBus(**properties: Any)

Superclasses: Object

Constructors:

TestDBus(**properties)
new(flags:Gio.TestDBusFlags) -> Gio.TestDBus

Constructors

class TestDBus
classmethod new(flags: TestDBusFlags) TestDBus

Create a new TestDBus object.

Parameters:

flags – a TestDBusFlags

Methods

class TestDBus
add_service_dir(path: str) None

Add a path where dbus-daemon will look up .service files. This can’t be called after up().

Parameters:

path – path to a directory containing .service files

down() None

Stop the session bus started by up().

This will wait for the singleton returned by bus_get() or bus_get_sync() to be destroyed. This is done to ensure that the next unit test won’t get a leaked singleton from this test.

get_bus_address() str | None

Get the address on which dbus-daemon is running. If up() has not been called yet, None is returned. This can be used with new_for_address().

get_flags() TestDBusFlags

Get the flags of the TestDBus object.

stop() None

Stop the session bus started by up().

Unlike down(), this won’t verify the DBusConnection singleton returned by bus_get() or bus_get_sync() is destroyed. Unit tests wanting to verify behaviour after the session bus has been stopped can use this function but should still call down() when done.

unset() None

Unset DISPLAY and DBUS_SESSION_BUS_ADDRESS env variables to ensure the test won’t use user’s session bus.

This is useful for unit tests that want to verify behaviour when no session bus is running. It is not necessary to call this if unit test already calls up() before acquiring the session bus.

up() None

Start a dbus-daemon instance and set DBUS_SESSION_BUS_ADDRESS. After this call, it is safe for unit tests to start sending messages on the session bus.

If this function is called from setup callback of test_add(), down() must be called in its teardown callback.

If this function is called from unit test’s main(), then down() must be called after test_run().

Properties

class TestDBus
props.flags: TestDBusFlags

TestDBusFlags specifying the behaviour of the D-Bus session.

Added in version 2.34.