Skip to content

@unpack, @file_data, and JSON list of lists #57

@interrogator

Description

@interrogator

Hi,

Great project, you've really improved our testing framework, thanks.

I appear to have found some unexpected behaviour when combining @file_data and @unpack when the JSON file contains a list of lists of strings.

Say I have j.json:

[ 
  ["some", "data"],
  ["another", "point"]
]

and example.py:

import unittest
from ddt import ddt, file_data, unpack

@ddt
class Tests(unittest.TestCase):

    @file_data('j.json')
    @unpack
    def test(self, first, second):
        return

unittest.main()

and run python example.py, I get an unexpected error:

Traceback (most recent call last):
  File "/.../py3/lib/python3.6/site-packages/ddt.py", line 139, in wrapper
    return func(self, *args, **kwargs)
TypeError: test() missing 1 required positional argument: 'second'

I would expect second to be "data" for the first generated test, then "point" for the second, but in fact, first contains a list, ["some", "data"], meaning that it wasn't unpacked . Is this behaviour a bug or feature? If bug, should I try to fix and PR?

Should point out: I know I could use dict/map structures in the JSON, but for our cases this is not desirable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions