获取csv数据 @pytest.mark.parametrize(读取数据)

获取csv数据,

@pytest.mark.parametrize(读取数据)

import csv
import pytest
# 生成列表中嵌套字典格式数据
def test_csv_01():
    with open("./data/password.csv", "r") as f:
        reader = csv.DictReader(f)
        data = []
        for row in reader:
            # print(row)
            data.append(row)
        # print(data)
        return data

# test_user_data = [{'username': '18600643222','password': '123456', 'verify_code': '8888'}]
#  方式三:参数为列表中嵌套字典
@pytest.mark.parametrize("case_info",test_csv_01())
# @pytest.mark.parametrize("case_info",test_user_data)
def test_login(case_info):
    print("\n")
    print("手机号", case_info['username'])
    print("密码", case_info['password'])
    print("验证码", case_info['verify_code'])

# # 生成列表格式数据
# def test_csv_02():
#     with open("./data/password.csv", "r") as f:
#         reader = csv.reader(f)
#         for row in reader:
#             print(row)


if __name__ == '__main__':
    pytest.main(['-sv','test_demo_03.py'])
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页