readConf.py
1.31 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
# -*- 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):
sections = self.conf.sections()
print(sections)
return sections
def returnOptions(self,options):
options = self.conf.options(options)
print(options)
return options
def returnOptionsInfo(self,items):
items = self.conf.items(items)
print(items)
def returnOptionsItems(self,options,items):
value = self.conf.get(options,items)
print(value)
return value
def ReturnFilePath(self):
print(self.file_path)
return self.file_path
# readConfig().returnOptionsItems("loginInfo","userName")