在一个函数调用中获得多个参数,但在另一个函数调用中没有
Got multiple Arguements in one function call but not in another function call
我正在研究 Robot Framework,我的基本方法之一是在 python 中编写的,用于构建具有 n 列和多个 where 条件的 SQL 查询。该函数看起来像,
from pypika import Query, Table, Field
def get_query_with_filter_conditions(table_name, *column, **where):
table_name_with_no_lock = table_name + ' with (nolock)'
table = Table(table_name_with_no_lock)
where_condition = get_where_condition(**where)
sql_query = Query.from_(table).select(
*column
).where(
Field(where_condition)
)
return str(sql_query).replace('"', '')
我在我的 Robot 关键字中调用此方法为:
Get Query With Filter Conditions ${tableName} ${column} &{tableFilter}
此函数在另外两个关键字中被调用。一方面,它工作正常。另一方面,它不断抛出错误
Keyword 'queryBuilderUtility.Get Query With Filter Conditions' got multiple values for argument 'table_name'.
效果不错的关键字如下:
Verify the ${element} in ${grid} is fetched from ${column} column in ${tableName} table from DB
[Documentation] Verifies Monetary values in the View Sale Grid
${feature}= Get Variable Value ${FEATURE_NAME}
${filterValue}= Get Variable value ${FILTER_VALUE}
${queryFilter}= Get the Test Data valid ${filterValue} ${feature}
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} ${filterValue}=${queryFilter}
Set To Dictionary ${tableFilter} form_of_payment_type=${element}
${tableName}= Catenate SEPARATOR=. SmartPRASales ${tableName}
${query}= Get query with Filter Conditions ${tableName} ${column} &{tableFilter}
Log ${query}
@{queryResult}= CommonPage.Get a Column values from DB ${query}
总是抛出错误的函数如下所示:
Verify ${element} drop down contains all values from ${column} column in ${tableName} table
[Documentation] To verify the drop down has all values from DB
${feature}= Get Variable Value ${FEATURE_NAME}
${filterElement}= Run Keyword If '${element}'=='batch_type' Set Variable transaction_type
... ELSE IF '${element}'=='channel' Set Variable agency_type
... ELSE Set Variable ${element}
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} table_name=GENERAL
Set To Dictionary ${tableFilter} column_name=${filterElement}
Set To Dictionary ${tableFilter} client_id=QR
Log ${tableFilter}
Log ${tableName}
Log ${column}
${tableName}= Catenate SEPARATOR=. SmartPRAMaster ${tableName}
${query}= Get Query With Filter Conditions ${tableName} ${column} &{tableFilter}
Log ${query}
@{expectedvalues}= CommonPage.Get a Column values from DB ${query}
有人可以帮我改正我在这里做错了什么吗?
问题出在字典中的键值对。字典中的关键字之一
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} table_name=GENERAL
与
中的参数之一相同
def get_query_with_filter_conditions(table_name, *column, **where):
将 get_query_with_filter_conditions 函数中的参数从 table_name 更改为 p_table_name 并且有效。由于该函数采用可以指定为命名参数的位置参数,因此 python 与我通过字典中的键 table_name 传递的 table_name 参数混淆了。
我正在研究 Robot Framework,我的基本方法之一是在 python 中编写的,用于构建具有 n 列和多个 where 条件的 SQL 查询。该函数看起来像,
from pypika import Query, Table, Field
def get_query_with_filter_conditions(table_name, *column, **where):
table_name_with_no_lock = table_name + ' with (nolock)'
table = Table(table_name_with_no_lock)
where_condition = get_where_condition(**where)
sql_query = Query.from_(table).select(
*column
).where(
Field(where_condition)
)
return str(sql_query).replace('"', '')
我在我的 Robot 关键字中调用此方法为:
Get Query With Filter Conditions ${tableName} ${column} &{tableFilter}
此函数在另外两个关键字中被调用。一方面,它工作正常。另一方面,它不断抛出错误
Keyword 'queryBuilderUtility.Get Query With Filter Conditions' got multiple values for argument 'table_name'.
效果不错的关键字如下:
Verify the ${element} in ${grid} is fetched from ${column} column in ${tableName} table from DB
[Documentation] Verifies Monetary values in the View Sale Grid
${feature}= Get Variable Value ${FEATURE_NAME}
${filterValue}= Get Variable value ${FILTER_VALUE}
${queryFilter}= Get the Test Data valid ${filterValue} ${feature}
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} ${filterValue}=${queryFilter}
Set To Dictionary ${tableFilter} form_of_payment_type=${element}
${tableName}= Catenate SEPARATOR=. SmartPRASales ${tableName}
${query}= Get query with Filter Conditions ${tableName} ${column} &{tableFilter}
Log ${query}
@{queryResult}= CommonPage.Get a Column values from DB ${query}
总是抛出错误的函数如下所示:
Verify ${element} drop down contains all values from ${column} column in ${tableName} table
[Documentation] To verify the drop down has all values from DB
${feature}= Get Variable Value ${FEATURE_NAME}
${filterElement}= Run Keyword If '${element}'=='batch_type' Set Variable transaction_type
... ELSE IF '${element}'=='channel' Set Variable agency_type
... ELSE Set Variable ${element}
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} table_name=GENERAL
Set To Dictionary ${tableFilter} column_name=${filterElement}
Set To Dictionary ${tableFilter} client_id=QR
Log ${tableFilter}
Log ${tableName}
Log ${column}
${tableName}= Catenate SEPARATOR=. SmartPRAMaster ${tableName}
${query}= Get Query With Filter Conditions ${tableName} ${column} &{tableFilter}
Log ${query}
@{expectedvalues}= CommonPage.Get a Column values from DB ${query}
有人可以帮我改正我在这里做错了什么吗?
问题出在字典中的键值对。字典中的关键字之一
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} table_name=GENERAL
与
中的参数之一相同def get_query_with_filter_conditions(table_name, *column, **where):
将 get_query_with_filter_conditions 函数中的参数从 table_name 更改为 p_table_name 并且有效。由于该函数采用可以指定为命名参数的位置参数,因此 python 与我通过字典中的键 table_name 传递的 table_name 参数混淆了。