How to make pytest to pass test if any parametrized test passed?

500 Views Asked by At

We have a cluster where only a single server (master) can return a meaningful result. The master is selected automatically and at test time I don't know who is master and who is not. In our tests we are using testinfra which gives us a fixture 'host' for each host in cluster.

We have a test which looks like this:

def test_cluster(host):
    assert host.run_command('cluster --is_ok').stdout == 'OK'

The problem is that there are N hosts, and only one of them can return OK, others says "I'm not a master".

The normal output looks like this:

test_cluster[host1] .... FAIL
test_cluster[host2] .... OK
test_cluster[host3] .... FAIL
test_cluster[host4] .... FAIL

I want to find a way to mark the test test_cluster as pass if any of tests is pass (and fail if all tests are failed).

If testinfra is too much for the test, here the more concise example with pytest only:

@pytest.fixture.parametrize("num", [0, 0, 1, 0])
def test_example(num):
     asssert num > 0

I need pytest to pass if there is at least one 1 in 'num' fixture.

0

There are 0 best solutions below