maho
maho

Reputation: 128

py.test and fixtures - how to choose only one variant of params

Let's say I have following fixtures:

@pytest.fixture(params=['google.com','other-provider.com')
def smtp_server(request):
    .... some initialisation ....
    return SmtpServer(request.param)


@pytest.fixture(params=['plain_text','html')
def message(request):
    .... some initialisation according to email type....
    return msg_obj

So if I use them in one test function, I have combination: google+plain, provider+plain, google+html, provider+html.

But what if I want to reuse fixtures, but only in specific combination. Eg I noticed that when I send html email to google, it fails under some circumstances. How can I reuse fixtures and test this situation, without testing sending to other-provider.com, which is pointless?

In other words - how to skip some combination of fixtures in specific test function?

Upvotes: 2

Views: 565

Answers (1)

flub
flub

Reputation: 6357

Firstly I'd like to point out this is actually a fairly odd case. Are you really sure the tests are not meaningful at all for the combinations you want to skip?

Having said that the way I have solved this myself is to simply use

if snmtp_server == 'other-provider.com' and message == 'html':
    pytest.skip('impossible combination')

inside the test function. It's rudimentary but works good enough for this unusual and rare case.

Upvotes: 1

Related Questions