【python接口自动化测试日期参数tips】

python接口自动化测试日期参数格式tips

  • 日期参数格式
    • 生成日期格式的代码

日期参数格式

我们在做Python接口自动化测试过程时,有的时候会遇到传参为日期格式的数据,日期格式多种多样,我们要确保符合要求的日期格式才能跑通接口。如果日期格式错误比如将“2024-02-06”写成“2024-2-6”那样就会报错

生成日期格式的代码

def generation_time():
    current_time = datetime.datetime.now()
    print(f'获取当前时间{current_time}')
    generate_time = current_time.strftime('%Y-%m-%d')
    print(generate_time)
    return generate_time

输出

获取当前时间2024-02-06 09:54:32.410465
2024-02-06

你可能感兴趣的:(python,开发语言)