测试用例脚本报错

file D:\sx_api\testcase\test_database_fdnfd_cache_add.py, line 9
      @user1ize("caseinfo",read_yaml_testcase("data/fdnfd_cache.yml"))
      def test_fdnfd_cache_add(self,base_url,caseinfo,connect_sql):
file D:\sx_api\testcase\conftest.py, line 20
  @pytest.fixture(scope="session",autouse=False)
  def connect_sql(db_alias):
E       fixture 'db_alias' not found
>       available fixtures: _verify_url, base_url, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, connect_sql, doctest_namespace, extra, get_token, include_metadata_in_junit_xml, log_init, metadata, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

测试用例脚本

class Test_FdNfd_Cache:
    @user3ize("caseinfo",read_yaml_testcase("data/fdnfd_cache.yml"))
    def test_fdnfd_cache_add(self,base_url,caseinfo,connect_sql):
        #通过输入库删除重复数据
        SQL = connect_sql("db_smoothly_supply")
        print(SQL)
        sql1 = "select * from fd_nfd_freight_rate_cache_mag WHERE CreatedBy='zhangxudong222'"
        res = SQL.exec(sql1)
        if res != None:
            sql = "DELETE FROM fd_nfd_freight_rate_cache_mag WHERE CreatedBy='zhangxudong222'"
            SQL.exec(sql)
        else:
            print("没有要删除的数据")
        method_info = caseinfo["request"]["method"]
        data_info = caseinfo["request"]["data"]
        caseinfo["request"]["data"]["tk"] = read_yaml("token")
        urlinfo = caseinfo["request"]["url"]
        url = base_url + urlinfo
        response = RequestUtil().send_all_request(method_info,url,json=data_info)

conftest 文件

#链接数据库固件
@pytest.fixture(scope="session",autouse=False)
def connect_sql(db_alias):
    print("链接数据库")
    init_db(db_alias)
    yield
    print("关闭数据库链接")
    Mysql().del_sql()

基础的读数据库的方法

#初始化数据库信息,通过配置
def init_db(db_alias):
    db_info = ConfigYaml().get_db_conf_info(db_alias)
    host=db_info["db_host"]
    user=db_info["db_user"]
    password=db_info["db_password"]
    db_name=db_info["db_name"]
    db_charset=db_info["db_charset"]
    port=int(db_info["db_port"])
    #初始化mysql对象
    conn = Mysql(host,user,password,db_name,db_charset,port)
    return conn


↙↙↙阅读原文可查看相关链接,并与作者交流