我在多个脚本中多次使用断言,我想知道是否有人对实现此目标的更好方法而不是我在下面创建的函数有任何建议。
def assert_validation(expected, actual, type='', message=''):
if type == '==':
assert expected == actual, 'Expected: %s, Actual: %s, %s' %(expected, actual, message)
elif type == '!=':
assert expected != actual, 'Expected: %s, Actual: %s, %s' %(expected, actual, message)
elif type == '<=':
assert expected <= actual, 'Expected: %s, Actual: %s, %s' %(expected, actual, message)
elif type == '>=':
assert expected >= actual, 'Expected: %s, Actual: %s, %s' %(expected, actual, message)
def assert_str_validation(expected, actual, type='', message=''):
if type == '==':
assert str(expected) == str(actual), 'Expected: %s, Actual: %s, %s' %(expected, actual, message)
elif type == '!=':
assert str(expected) != str(actual), 'Expected: %s, Actual: %s, %s' %(expected, actual, message)
elif type == '<=':
assert str(expected) <= str(actual), 'Expected: %s, Actual: %s, %s' %(expected, actual, message)
elif type == '>=':
assert str(expected) >= str(actual), 'Expected: %s, Actual: %s, %s' %(expected, actual, message)