readConf.py
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
# @Time : 2021/7/16 10:36
# @Author : Ljq
# @File : readConf.py
# @Software: PyCharm
"""
配置文件读取
"""
import configparser
import os
class readConfig(object):
ROBOT_LIBRARY_SCOPE = 'TEST CASE'
ROBOT_LIBRARY_VERSION = '0.1'
def __init__(self):
# 按市场读取配置文件数据
self.conf = configparser.ConfigParser()
self.evn_name = os.name
self.file_name = r'test_config_hg.conf'
self.relative_path = r'/config/marketConfig/'
self.file_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../")) + self.relative_path + self.file_name
print(self.file_path)
self.conf.read(self.file_path,encoding="utf-8")
def returnSections(self):
# 读取所有的options选项
sections = self.conf.sections()
print(sections)
return sections
def returnOptions(self,options):
# 通过options读取所有items
options = self.conf.options(options)
print(options)
return options
def returnOptionsInfo(self,options):
# 通过options读取相关的items和value
items = self.conf.items(options)
print(items)
def returnOptionsItems(self,options,items):
# 通过options和items的组合关系读取对应的value
value = self.conf.get(options,items)
print(value)
return value
def ReturnFilePath(self):
print(self.file_path)
return self.file_path
# rc = readConfig()
# rc.returnSections()
# rc.returnOptions("loginInfo")
# rc.returnOptionsInfo("loginInfo")
# rc.returnOptionsItems("loginInfo","username")
# rc.ReturnFilePath()