So I have the following function which I am trying to unit test:
def _extract_celery_task_args(*args: tuple, **kwargs: dict):
....
I tried something like:
def test_extract_celery_task_args_max_four_args(mock_ConvertToParsingIntDate):
args = ('task', 'parser_code', 'group_name', 'date')
kwargs = {'mic': 'XEUR', 'something': 'else'}
try:
_extract_celery_task_args(args, kwargs)
except ValueError as ve:
assert False, ("More than 4 positional arguments passed to _extract_celery_task_args"
"function")
But when I set a breakpoint inside _extract_celery_task_args
and print out args
and kwargs
, I get:
args = (('task', 'parser_code', 'group_name', 'date'), {'mic': 'XEUR', 'something': 'else'})
kwargs = {}
Am I passing in kwargs
wrongly?
_extract_celery_task_args(args, kwargs)
, which means the args
variable will be treated as a single argument, and the kwargs
variable will be treated as an empty dictionary._extract_celery_task_args(*args, **kwargs)
*args
and **kwargs
, individual elements of args
will be passed as separate positional arguments, and the key-value pairs in kwargs
will be passed as keyword arguments.