robotframework-faker icon indicating copy to clipboard operation
robotframework-faker copied to clipboard

Adding a custom provider fails with error: "set_formatter() takes exactly 3 arguments (2 given)"

Open kootstra opened this issue 7 years ago • 0 comments

When I run the following code, I'm facing some difficulty. Calling the Add Provider keyword requires two arguments, instead of the expected 1: name of the module. This seems to me to be correct.

Assuming it might be the FakerLibrary I retrieved it's library instance and provided it to the keyword. Sadly this doesn't provide me with the desired end result but instead generates the error: "FAIL : TypeError: set_formatter() takes exactly 3 arguments (2 given)".

The Robot Script for this example.

*** Settings ***
Library    FakerLibrary    
*** Test Cases ***
Faker Custom Provider Generate Data
    
    ${fakerLib}    Get Library Instance    FakerLibrary
    Add Provider    ${fakerLib}    OceanProvider

The custom provider Python code:

from faker.providers import BaseProvider

class OceanProvider(BaseProvider):

    __provider__ = "ocean"
    __lang__     = "en_US"

    oceans = [
        u'Atlantic', u'Pacific', u'Indian', u'Arctic', u'Southern',
    ]

    @classmethod
    def ocean(cls):
        return cls.random_element(cls.oceans)

kootstra avatar Nov 02 '17 14:11 kootstra