plugins – Testsuite plugins

Plugins to support the pyudev testsuite.

The following plugins are provided and enabled:

privileged – Privileged operations

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:

fake_monitor – A fake Monitor

Funcargs

The plugin provides the following funcargs:

mock_libudev – Mock calls to libudev

travis – 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: