I have a function that doesn't "return" anything but relies on altering a dictionary/list using its mutability. i.e.:
def func(my_list):
my_list.append(4)
I want to test this function using pytest and parameterisation:
@pytest.mark.parametrize("input1, result", [
([1], [1, 4]),
([33, 44], [33,44, 4])
])
def test_mytest(input1, result):
assert func(input1) == result
Problem is, this obviously won't work because my function doesn't actually "return" my_list
. Is it possible to test the value of my_list
using pytest, and if so how?
You could compare the value of list1 to result after
the call to the function.
def test_mytest(input1):
func(input1)
assert input1 == result
Note that input1 will be modified after the call to the function and can now be compared to the expected result
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments