txels/ddt — pull request #22 by garymacindoe (2014-10-28 12:23:32+00:00)
Title: Add ability to parse dicts of dicts in JSON to pass kwargs.

I have test functions with a large number of arguments:

def test_function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9):
pass

Using the current version of ddt I can write my test cases as a dict of lists in JSON and get reasonably predictable automatically generated test names:

{
"test_case1": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
"test_case2": [ 0, 9, 8, 7, 6, 5, 4, 3, 2, 1 ]
}

Due to the large number of arguments involved it rapidly becomes confusing mapping each argument value in the list to each named argument in the test function and it also makes refactoring the test function (specifically reordering the arguments) near impossible.

I have added a few lines to ddt which check whether the test arguments are a dict and passes them to the test function as kwargs rather than assuming they will always be a list and passing them as args. This allows me to specify my test cases as a dict of dicts in JSON with named arguments while retaining predictable test case names and allowing the reordering of arguments in the test function:

{
"test_case1": { "arg0": 0,
"arg1": 1,
"arg2": 2,
"arg3": 3,
"arg4": 4,
"arg5": 5,
"arg6": 6,
"arg7": 7,
"arg8": 8,
"arg9": 9 },
"test_case2": { "arg0": 0,
"arg1": 9,
"arg2": 8,
"arg3": 7,
"arg4": 6,
"arg5": 5,
"arg6": 4,
"arg7": 3,
"arg8": 2,
"arg9": 1 }
}