pytest - Ignore test, not just skip

341 Views Asked by At

I am using testinfra to test if some services is running/enabled on different nodes. Testinfra can use ansible for getting the nodes to test and it will also make ansible groups available. Testinfra uses pytest.

I only want to test for services on very few ansible groups and the code looks like this.

import pytest
import testinfra

group_service_map = [
    ('group1', 'svc1'),
    ('group1', 'svc2'),
    ('group2', 'svc3')
]

@pytest.fixture
def host_groups(host):
    return host.ansible.get_variables()['group_names']

@pytest.mark.parametrize('check', ('running', 'enabled'))
@pytest.mark.parametrize('group, service', group_service_map)
def test_service_running(host, check, host_groups, group, service):
    if group in host_groups:
        assert getattr(host.service(service), f'is_{check}') is True, f'{service} is not {check}'

This works great, except that pytest things that I got 1 passing test for each time test_service_running is called (which is a lot, since this is a parametrized test). I tried adding a pytest.skip(), but then pytest shows the tests as skipped (yellow s).

The goal is to ignore the test in the output, not just skip it. So instead of a green or yellow ., I want nothing.

I've read the api-docs and in the source, but can't find any info if this is even possible.

I'll make a pull-request, but wanted to check first if anyone know of a solution.

0

There are 0 best solutions below