Python之常见报错missing 2 required positional arguments的2种问题排查方法

报错:TypeError: wait_assert_sql() missing 2 required positional arguments: 'assert_sql' and 'value'

@property
def wait_assert_sql(self, assert_sql, value):
    print("assert_sql")
    print("value")
Request.wait_assert_sql(assert_sql="select", value=2)

分析原因1:

由@property 装饰后,调用函数时不需要填写参数。因为调用时,填写了参数,所以出现了报错

报错:TypeError: wait_assert_sql() missing 2 required positional arguments: 'assert_sql' and 'value'

def wait_assert_sql(self, assert_sql, value):
    print("assert_sql")
    print("value")
Request.wait_assert_sql()

分析原因2:

定义函数时,有传参,调用时也需要有传参

修改后:

def wait_assert_sql(self, assert_sql, value):
    print("assert_sql")
    print("value")
Request.wait_assert_sql(assert_sql="select", value=2)

修改如上后,可以正常执行,不会有报错

你可能感兴趣的:(接口自动化实践,python)