python自动化运维软件测试测试员的那点事

Python 自动化测试实战 Zero to Hero 基础 读

2019-12-23  本文已影响0人  伊洛的小屋

无论做自动化测试还是测试开发或者其它工作中,肯定需要做一些配置并在程序中读取这些预设置好的配置内容,那么最常用的无疑是ini配置文件了

本文首发于伊洛的个人博客:https://yiluotalk.com,欢迎关注并查看更多内容!!!

1. ini配置文件
[section_1]
option_1 = value_1
option_2 = value_2
[section_2]
2. python读取配置文件
# 伊洛Yiluo
# 自动化测试配置文件

[test]
# 测试人
tester = yiluo
# 测试环境
environment = test
# 测试版本
versionCode = 1.0.0

host = https://test.yiluotalk.com


[release]
tester = luoyi
environment = release
versionCode = 2.0.0
# 正式域名(伊洛的个人博客)
host = https://yiluotalk.com
In [1]: from configparser import ConfigParser

In [2]: config = ConfigParser()
In [3]: config.read('test.ini')
Out[3]: ['test.ini']

In [10]: config.sections()
Out[10]: ['test', 'release']
In [7]: config.has_section('test')
Out[7]: True
In [12]: config.has_section('demo')
Out[12]: False
In [14]: config.options('test')
Out[14]: ['tester', 'environment', 'versioncode', 'host']
In [16]: config.get('release', 'host')
Out[16]: 'https://yiluotalk.com'

欢迎下方【戳一下】【点赞】
Author:伊洛Yiluo
愿你享受每一天,Just Enjoy !

上一篇下一篇

猜你喜欢

热点阅读