2

How can I pass a function as a parameter in Python? I want to do something like the code below.

My goal is to pass different parameters to test a single function.

def __internal_function(inputs):
    a,b,c,d = inputs

    new_value_of_b = copy.deepcopy(b)

    name = b['name']
    age = b['age']
    weight = b['weight']
    height = b['height']

    new_value_of_b2 = [name, age, weight, height]
    new_value_of_b3= new_value_of_b['weight']['unit'] = 'cm'
    del new_value_of_b['age']
    return new_value_of_b,new_value_of_b2,new_value_of_b3


@pytest.mark.parametrize('values',__internal_function,'expected_code',[100,200,300])
assert func(__internal_function)== expected_code

1 Answers1

0

If you are using two variables as parameters, the correct syntax is:

@pytest.mark.parametrize(('values','expected_code'),(_internal_function,[100,200,300]))

You can use function as a parameter if its output is an iterable.

SilentGuy
  • 1,867
  • 17
  • 27