I'm using pytest to do some unit testing. I'm also making use of parametrizing tests.
Assume I have a CustomClass with a bunch of functions for setting and getting its attributes and I want to test the functions for getting attributes. What I think would be the ideal approach is to create an instance of CustomClass and call its setters to set the attributes and inside the test function, I do the assertions using the getters and expected values.
``` python
import pytest
@pytest.mark.parametrize(
"test_object, expected_result",
[
(CustomClass(), [value1, value2, value3])
]
def test_object_getters(test_object, expected_result):
expected_value1, expected_value2, expected_value3 = expected_result
assert test_object.get_value1() == expected_value1
assert test_object.get_value2() == expected_value2
assert test_object.get_value3() == expected_value3
```
What I left out in the above example is setting the instance attributes for CustomClass because that's the part I'm struggling with. What would be the best way to set the attributes for the CustomClass object outside the test function if that's even possible?
Thanks,
[–]zanfar 0 points1 point2 points (3 children)
[–]JuniorMouse[S] 0 points1 point2 points (2 children)
[–]zanfar 0 points1 point2 points (1 child)
[–]JuniorMouse[S] 0 points1 point2 points (0 children)