妗嗘灦鍋ュ.鎬т紭鍖栵紝鐜鍙橀噺绫伙紝姝e垯鏇挎崲excel

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了妗嗘灦鍋ュ.鎬т紭鍖栵紝鐜鍙橀噺绫伙紝姝e垯鏇挎崲excel相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%9d%a1%e4%bb%b6' title='鏉′欢'>鏉′欢   test   header   姝e垯   preview   common   瀵硅薄   杩囩▼   headers   

椤圭洰鍋ュ.鎬ф彁楂?path鍙傛暟鍖?/h1>
import os

# 鑾峰彇椤圭洰鎵€鍦ㄧ殑缁濆璺緞
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# 鐢ㄤ緥妯″潡鎵€鍦ㄧ殑鐩綍璺緞
CASE_DIR = os.path.join(BASE_DIR, "testcases")

# 鐢ㄤ緥鏁版嵁鎵€鍦ㄧ殑鐩綍璺緞
DATA_DIR = os.path.join(BASE_DIR, "data")

# 閰嶇疆鏂囦欢鎵€鍦ㄧ殑鐩綍璺緞
CONF_DIR = os.path.join(BASE_DIR, "conf")

# 娴嬭瘯鎶ュ憡鎵€鍦ㄧ殑鐩綍璺緞
REPORT_DIR = os.path.join(BASE_DIR, "reports")

# 鏃ュ織鏂囦欢鎵€鍦ㄧ殑鐩綍璺緞
LOG_DIR = os.path.join(BASE_DIR, "logs")

寮曞叆姝e垯鏂逛究瀵筫xcel涓殑鏁版嵁鐏垫椿鏇挎崲瀹屽杽鍙傛暟鍖栨晥鏋?/h1>
import re
from common.handle_config import conf


class EnvData:
    """瀹氫箟涓€涓被锛岀敤鏉ヤ繚瀛樼敤渚嬫墽琛岃繃绋嬩腑锛屾彁鍙栧嚭鏉ョ殑鏁版嵁锛堝綋鎴愮幆澧冨彉閲忕殑瀹瑰櫒锛?""
    pass




def replace_data(data):
    """鏇挎崲鏁版嵁"""

    while re.search("#(.*?)#", data):
        res = re.search("#(.*?)#", data)
        # 杩斿洖鐨勫紡涓€涓尮閰嶅璞?        # 鑾峰彇鍖归厤鍒扮殑鏁版嵁
        key = res.group()
        # 鑾峰彇鍖归厤瑙勫垯涓嫭鍙烽噷闈㈢殑鍐呭
        item = res.group(1)
        try:
            # 鑾峰彇閰嶇疆鏂囦欢涓搴旂殑鍊?            value = conf.get("test_data", item)
        except:
            # 鍘籈nvData杩欎釜绫婚噷闈㈣幏鍙栧搴旂殑灞炴€э紙鐜鍙橀噺锛?            value = getattr(EnvData, item)

        data = data.replace(key, value)
    return data

鐜鍙橀噺绫荤殑瀹為檯搴旂敤

瀹炰緥浠g爜

@ddt
class TestAdd(unittest.TestCase):
    excel = HandleExcel(os.path.join(DATA_DIR, "apicases.xlsx"), "add")
    cases = excel.read_data()
    db = Handlemysql()

    @classmethod
    def setUpClass(cls):
        """鐢ㄤ緥鎵ц鐨勫墠缃潯浠讹細鐧诲綍"""
        # 鍑嗗鐧诲綍鐨勭浉鍏虫暟鎹?        url = conf.get("env", "url") + "/member/login"
        data = {
            "mobile_phone": conf.get("test_data", "phone"),
            "pwd": conf.get("test_data", "pwd")
        }
        headers = eval(conf.get("env", "headers"))
        response = request(method="post", url=url, json=data, headers=headers)
        res = response.json()
        member_id = str(jsonpath.jsonpath(res, "$..id")[0])
        token = "Bearer" + " " + jsonpath.jsonpath(res, "$..token")[0]
        # 灏嗘彁鍙栧嚭鏉ョ殑鏁版嵁淇濆瓨涓篍nvData杩欎釜绫荤殑灞炴€э紙鐜鍙橀噺锛?        setattr(EnvData, "member_id", member_id)
        setattr(EnvData, "token", token)

以上是关于妗嗘灦鍋ュ.鎬т紭鍖栵紝鐜鍙橀噺绫伙紝姝e垯鏇挎崲excel的主要内容,如果未能解决你的问题,请参考以下文章

Python Django妗嗘灦瀹炵幇鍟嗗煄椤圭洰婧愮爜鍔犺璁℃枃妗e拰娉ㄩ噴

React Status 涓枃鍛ㄥ垔 #39 - 浜斿ぇ React 妗嗘灦娴嬭瘎

浜笢璺ㄧ缁熶竴妗嗘灦 Taro 1.3 姝e紡鍙戝竷锛氬紩鍏lutter Doctor 锛屽叏闈㈡敮鎸丷eact Hooks鍜孞SX锛屽揩搴旂敤

鍐呮牳妯″潡鍙傛暟璁捐

python鍙橀噺

js鏃ユ湡鏍煎紡鍖栵紝宸ュ叿绫讳腑