Skip to content
Snippets Groups Projects
Commit 357ed3a95baa authored by Martijn Pieters's avatar Martijn Pieters
Browse files

utils: add a decorator to move positional param args to keyword args

Usage:

```
class TestSuite(BaseTestSuite):
    params = BaseTestSuite.params + [foo_values, bar_values]
    param_names = BaseTestSuite.param_names + ['foo', 'bar']

    @params_as_kwargs
    def test_name(self, foo, bar, **kwargs):
        # ...

and you no longer have to worry about other parameters in BaseTestSuite.params.
parent fdff9b6ce641
No related branches found
No related tags found
No related merge requests found
from __future__ import print_function from __future__ import print_function
import json import json
import functools
import os import os
import os.path import os.path
import re import re
...@@ -115,6 +116,22 @@ ...@@ -115,6 +116,22 @@
return sum(sorted(lst)[quotient - 1:quotient + 1]) / 2. return sum(sorted(lst)[quotient - 1:quotient + 1]) / 2.
def params_as_kwargs(f):
"""Pass in test parameters as keyword arguments.
Use as a decorator on BaseTestSuite methods
"""
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
names = self.param_names
args, values = args[len(names):], args[:len(names)]
kwargs.update(zip(names, values))
return f(self, *args, **kwargs)
return wrapper
class BaseTestSuite(object): class BaseTestSuite(object):
params = [REPOS] params = [REPOS]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment