How is it right to transfer the crust mass to the method through annotation that requires callable?



  • Trying to write a parameterized test, using it. itertoolsunittest_data_provider

    There are two data sets: REQUESTSLOCALES♪ In each of the several elements.

    REQUESTS = [
        {
            'name': 'string',
            'request': {'object': 'data'}
        }
    ]
    

    LOCALES = [
    {
    'name': 'string',
    'json': {'object': 'data'},
    'pattern': 'string'
    }
    ]

    I get his decarto work:

    # Cartesian product of input iterables.  Equivalent to nested for-loops.
    PRODUCT = itertools.product(REQUESTS, LOCALES)

    He's got it on the seal. As I expect, there's a cortege inside and there are two elements.

    test = ({
    'request': {'object': 'data'},
    'name': 'string'
    },
    {
    'pattern': u'string',
    'json': {'object': 'data'},
    'name': 'string'
    })

    Now there's a test method to get the data. I made some attempts to give him the data. One, naive. I want to hand over the box, and then I'll take it inside the method:

    @data_provider(itertools.product(REQUESTS, LOCALE_SETS))
    def test_locale(self, data):

    TypeError: 'itertools.product' object is not callable

    Suggested that the method required was to deliver elements from the mass:

    @data_provider(itertools.product(REQUESTS, LOCALES).next)
    def test_locale(self, data):

    TypeError: test_locale() takes exactly 2 arguments (3 given)

    Do both elements of the correlation seem to be transmitted as separate arguments of the method?

    @data_provider(itertools.product(REQUESTS, LOCALES).next)
    def test_locale(self, request_data, locale_data):

    TypeError: test_locale() takes exactly 3 arguments (4 given)

    What's going on? I only changed the method's signature, but now it's a bigger argument?

    What are the two rows supposed to be, so that one set of two sets of data from the dekarta production of the two sets is transferred to each challenge of the method? I don't care if this is one argument, two or five.


    Thought I'd find out how many arguments were made:

    @data_provider(itertools.product(REQUESTS, LOCALES).next)
    def test_locale(self, *args):
    for i in args:
    print i

    Result:

    request
    name
    pattern
    json
    name

    All right, five of them!

    @data_provider(itertools.product(REQUESTS, LOCALES).next)
    def test_locale(self, request, request_name, locale_pattern, locale_json, locale_name):

    TypeError: test_locale() takes exactly 6 arguments (3 given)

    Why are they three again?



  • Turns out I misunderstood the callable. The facility to be transferred to the decorator will not be repeated (which implies use) .nextand one day. Therefore, the right decision will be to declare the Lambadu:

    @data_provider(lambda: itertools.product(REQUESTS, LOCALES))
    def test_locale(self, request_data, locale_data):
    

    The mass inside of the cortuaries is now transmitted in every two dictionaries. And before, one ship came from this body.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2