I have a list of dicts:
JavaScript
x
5
1
MY_LIST = [
2
{ 'key1': {'a': 1, 'b':2 } },
3
{ 'key2': {'a': 1, 'b':2 } }
4
]
5
How do I pass the dict to a django unit test using parameterized? E.g.
JavaScript
1
4
1
@parameterized.expand(MY_LIST):
2
def test_mytest(self, dict_item):
3
print(dict_item.items())
4
Results in AttributeError: 'str' object has no attribute 'items'
because the dict is being converted to a string.
Advertisement
Answer
As stated in the docs:
JavaScript
1
2
1
The @parameterized and @parameterized.expand decorators accept a list or iterable of tuples or param( ), or a callable which returns a list or iterable
2
So I would try to convert MY_LIST
to:
JavaScript
1
5
1
MY_LIST = [
2
({ 'key1': {'a': 1, 'b': 2}},),
3
({ 'key2': {'a': 1, 'b': 2}},),
4
]
5
Which makes it a list of tuples that contain a single parameter to apply to the method you are testing.