plugins – Testsuite plugins

Plugins to support the pyudev testsuite.

The following plugins are provided and enabled:

privileged – Privileged operations

Support privileged operations to trigger real udev events.

This plugin adds load_dummy() and unload_dummy() to the pytest namespace.

Command line options

The plugin adds the following command line options to py.test:

--enable-privileged

Enable privileged tests. You’ll need to have sudo configured correctly in order to run tests with this option.

Configuration

In order to execute these tests without failure, you need to configure sudo to allow the user that executes the test to run the following commands:

  • modprobe dummy
  • modprobe -r dummy

To do so, create a file /etc/sudoers.d/20pyudev-tests with the following content:

me ALL = (root) NOPASSWD: /sbin/modprobe dummy, /sbin/modprobe -r dummy

Replace me with your actual user name. NOPASSWD: tells sudo not to ask for a password when executing these commands. This is simply for the sake of convenience and to allow unattended test execution. Remove this word if you want to be asked for a password.

Make sure to change the owner and group to root:root and the permissions of this file to 440 afterwards, other sudo will refuse to load the file. Also check the file with visudo to prevent syntactic errors:

$ chown root:root /etc/sudoers.d/20pyudev-tests
$ chmod 440 /etc/sudoers.d/20pyudev-tests
$ visudo -c -f /etc/sudoers.d/20pyudev-tests

pytest namespace

The plugin adds the following functions to the pytest namespace:

plugins.privileged.load_dummy()

Load the dummy module.

If privileged tests are disabled, the current test is skipped.

plugins.privileged.unload_dummy()

Unload the dummy module.

If privileged tests are disabled, the current test is skipped.

fake_monitor – A fake Monitor

Provide a fake Monitor.

This fake monitor allows to trigger arbitrary events. Use this class to test class building upon monitor without the need to rely on real events generated by privileged operations as provided by the privileged plugin.

class plugins.fake_monitor.FakeMonitor(device_to_emit)

A fake Monitor which allows you to trigger arbitrary events.

This fake monitor implements the complete Monitor interface and works on real file descriptors so that you can select() the monitor.

close()

Close sockets acquired by this monitor.

trigger_event()

Trigger an event on clients of this monitor.

Funcargs

The plugin provides the following funcargs:

plugins.fake_monitor.fake_monitor(request)

Return a FakeMonitor, which emits the platform device as returned by the fake_monitor_device funcarg on all triggered actions.

Warning

To use this funcarg, you have to provide the fake_monitor_device funcarg!

mock_libudev – Mock calls to libudev

Plugin to mock calls to libudev.

This plugin adds libudev_list() to the pytest namespace.

plugins.mock_libudev.libudev_list(function, items)

Mock a libudev linked list:

with pytest.libudev_list(device._libudev, 'udev_device_get_tag_list_entry', ['foo', 'bar']):
    assert list(device.tags) == ['foo', 'bar']

function is a string containing the name of the libudev function that returns the list. items is an iterable yielding items which shall be returned by the mocked list function. An item in items can either be a tuple with two components, where the first component is the item name, and the second the item value, or a single element, which is the item name. The item value is None in this case.

travis – Support for Travis CI

Support for Travis CI.

Test markers

pytest.mark.not_on_travis

Do not run the decorated test on Travis CI:

@pytest.mark.not_on_travis
def test_foo():
    assert True

test_foo will not be run on Travis CI.

pytest namespace

The plugin adds the following functions to the pytest namespace:

plugins.travis.is_on_travis_ci()

Determine whether the tests run on Travis CI.

Return True, if so, or False otherwise.