I have read several topics with similar problem, but I don't understand the error is thrown in my case.
I have a class method:
def submit_new_account_form(self, **credentials):
...
When I call it on an instance of my object like this:
create_new_account = loginpage.submit_new_account_form(
{'first_name': 'Test', 'last_name': 'Test', 'phone_or_email':
temp_email, 'newpass': '1q2w3e4r5t',
'sex': 'male'})
I receive this error:
line 22, in test_new_account_succes
'sex': 'male'})
TypeError: submit_new_account_form() takes 1 positional argument but 2 were
given
Well that is logical: **credentials
means that you will provide it named arguments. But you do not provide a name for the dictionary.
There are two possibilities here:
you use credentials
as a single argument, and pass it the dictionary, like:
def submit_new_account_form(self, credentials):
# ...
pass
loginpage.submit_new_account_form({'first_name': 'Test', 'last_name': 'Test', 'phone_or_email': temp_email, 'newpass': '1q2w3e4r5t', 'sex': 'male'})
you pass the dictionary as named arguments, by putting two asterisks in front:
def submit_new_account_form(self, **credentials):
# ...
pass
loginpage.submit_new_account_form(**{'first_name': 'Test', 'last_name': 'Test', 'phone_or_email': temp_email, 'newpass': '1q2w3e4r5t', 'sex': 'male'})
The second approach is equal to passing named arguments like:
loginpage.submit_new_account_form(first_name='Test', last_name='Test', phone_or_email=temp_email, newpass='1q2w3e4r5t', sex='male')
I think the last way to call this is cleaner syntax. Furthermore it allows you to easily modify the signature of the submit_new_account_form
function signature to catch certain parameters immediately, instead of wrapping them into a dictionary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With