0

Within Pytest, I'd like to have two different parameter sets:

    "unit_type_a" = [
        'a-param1',
        'a-param2',
        'a-param3'
    ]
    "unit_type_b" = [
        'b-param1',
        'b-param2',
        'b-param3',
        'b-param4'
    ]

Then based on the pytest runner options (--unit_type=<a,b>), I'd pull this unit_type option and use this for selecting the appropriate parameter set to use in test.

Here's what I have but stuck how to get command line option within this get_params() function:

def get_params():

# how to get unit type from command line option?  
# I've tried using conftest fixture `def get_parms(get_unit_type)` here but see errors because test parameterize get_params() also needs this fixture value but isn't liking it.  
# I've tried to create a module fixture to get this option but then I can't call module fixtures in functions.
# unit_type = ???

test_param_map = {
    "unita": [
        'a-param1',
        'a-param2'
    ],
    "unitb": [
        'b-param1',
        'b-param2',
        'b-param3'
    ]
}
return test_param_map[unit_type]

@pytest.mark.parametrize('test_params', get_params())
def test_select_params(test_params):

   pass

I've seen some people talk about using special pytest function pytest_generate_tests. Is this the route that I should look into? If so, any sample code, would be helpful.

seahawk
  • 1
  • 4

0 Answers0