What are the ways to use different fixtures with different scopes at the same time without conflicts that pytest offers

108 views Asked by At

Problem:

I want to hide @pytest.mark.parametrize so that the tests look neat, I'm looking for other implementation

Describe:

  1. What I have:
@pytest.mark.parametrize('testcase', ['C34744: Switch to all size'
                                      'C34742: Switch to all duration',
                                      'C34743: Switch to all members'])
@pytest.mark.parametrize('auth_f', [''], indirect=True, scope='function')
@pytest.mark.parametrize('conference_f', ['testsuite_switch_filters'], indirect=True, scope='function')
def testsuite(self, auth_f, conference_f, testcase):
    results = execute_actions('testsuite', testcase, auth_f)
    assert not results, "problems occured: " + results

This configuration is working for me. But I doubt about the correctness of this approach. And I would like to hide the extra @pytest.mark.parametrize. Are there any other ways to implement such a mechanism?

There are 2 fixtures (auth_f, conference_f) that I can run with all kinds of scopes. For me, the main thing is that they do not conflict with each other. In this case, I can use:

first_fixt(scope) second_fixt(scope)
function function
module function
function module
module module

How else such behavior can be achieved? In a case when one fixture depends on another (e.g: conference_f(auth_f)), I cannot use scopes so widely, because I will have a conflict.

  1. How I wanted it to be:
@pytest.mark.parametrize('testcase', ['C34744: Switch to all size'
                                      'C34742: Switch to all duration',
                                      'C34743: Switch to all members'])
def testsuite(self, auth_f, conference_f, testcase):
    results = execute_actions('testsuite', testcase, auth_f)
    assert not results, "problems occured: " + results

Without the following oprions:

@pytest.mark.parametrize('auth_f', [''], indirect=True, scope='function')
@pytest.mark.parametrize('conference_f', ['testsuite_switch_filters'], indirect=True, scope='function')
0

There are 0 answers