How to make automated tests for clients of D-Bus system service?

Miroslav Kravec kravec.miroslav at gmail.com
Tue Feb 6 14:31:58 UTC 2018


On Tue, Feb 6, 2018 at 2:46 PM, Simon McVittie <smcv at collabora.com> wrote:
> On Tue, 06 Feb 2018 at 14:32:49 +0100, Miroslav Kravec wrote:
>> How do I start own dbus-daemon?
>
> Look at how python-dbusmock does it (I think it has convenience code to
> do that for you?), or at the other examples I linked. The tl;dr version
> is something like this:
>
>     dbus-daemon --fork --config=your-config-file-here \
>         --print-address=3 --print-pid=4 3>address.txt 4>pid.txt
>
> Now your bus address is in address.txt, and the process ID to kill
> afterwards is in pid.txt. (Or use pipes.)
>
>> $ dbus-daemon --print-address
>> No configuration file specified.
>
> You'll need a configuration file that looks like a hybrid of the session
> bus and the system bus, and optionally picks up .service files from a
> directory that you control (or you can run the mock service explicitly
> and wait for it to appear instead). python-dbusmock probably has some
> examples of this.  If not, test/name-test/tmp-session-like-system.conf
> in dbus.git is the sort of thing I mean.


Well, this looks like complicated way to do it.

I have tried python3-dbusmock, and it's quite easy. As shown in
example in project's README, it starts system bus, allows me to spawn
custom server (service), and mock methods. And, subprocess.run is
working as expect without any extra effort needed.


More information about the dbus mailing list