1.添加一个config.ini文件:
[test]
url = http://192.168.8.231:8000
2.编写用例时获取url:
import getcwd
import os
import configparser
# 从配置文件获取URL
path = getcwd.get_cwd()
config_path = os.path.join(path, 'config.ini')
config = configparser.ConfigParser()
config.read(config_path, encoding="utf-8-sig")
config_url = config.get('test', 'url')
# 访问接口
url = config_url + '/index/login' # 本地