场景:请求获取验证码模块regVC.py读取配置文件config.ini时,regVC.py模块单独执行正常,但通过run_all.py模块批量执行时报错,找不到section

解决办法:配置文件路径需写绝对路径

config.ini文件如下:

regVC.py模块代码如下:

 import requests
import configparser
import unittest
from Case.readexcel import ExcelData
import json class registerVerifyCode(unittest.TestCase):
def setUp(self):
self.Purl = "/api/register/getVerifyCode"
#取配置文件内数据
self.config = configparser.ConfigParser()
self.text = self.config.read("F:\\Case\\config.ini") #这里要写配置文件的绝对路径
self.section = self.config.sections()
self.option = self.config.options("section_1")
self.item = self.config.items("section_1")
self.url = self.config.items("section_1")[1][1]+self.Purl
self.headers = self.config.items("section_1")[0][1]
#self.headers由str类型转化为字典类型
self.header = eval(self.headers)
self.data_path = self.config.items("section_1")[2][1]
self.sheetname = "注册验证码获取"
self.data = ExcelData(self.data_path,self.sheetname).readExcel()
print(self.url)
print(self.data) def test_reVC(self):
for a in self.data:
for b in a:
print(a)
print(b)
par = {"data":{
b:a[b]
}
}
print(par)
par_json = json.dumps(par)
res = requests.post(self.url,par_json,headers=self.header)
print(res.text)
if "手机号码已注册" in res.text:
print("该手机号码已注册")
if "请求注册验证码成功" in res.text:
print("请求注册验证码成功") if __name__ == '__main__':
unittest.main()

run_all.py代码如下:

 import unittest

 def all_case():
case_dir = "F:\\KEJINSUO_interface\\Case\\"
testCase = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(case_dir, pattern = "reg*.py", top_level_dir = None)
testCase.addTest(discover)
return testCase if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(all_case())

代码需慢慢优化,先实现简单的功能

python执行报错 configparser.NoSectionError: No section: 'section_1'的更多相关文章

  1. python 读取配置文件总是报错 configparser.NoSectionError: No section:

    本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...

  2. 第一次打开pycharm运行python文件报错”No Python interpreter selected“问题的解决办法

    前面没有细讲,这里细述一下安装pycharm后,第一次打开pycharm运行python文件报错"No Python interpreter selected"问题的解决办法. 出 ...

  3. oracle创建包后执行报错:object omgmig.test_package is invalid.

    今天学习了一下oracle的包的写法,然后碰到这么个问题.包声明和包主体都正确,但是就是执行报错:object omgmig.test_package is invalid. 这是会报错的sql,看起 ...

  4. salt执行报错一例

    执行报错: 查看服务端日志: 认证有问题 重新认证吧!!! minion端: [root@super66 ~]# cd /etc/salt/[root@super66 salt]# lsminion ...

  5. Ubuntu下sh *.sh使用==操作符执行报错

    ----<鸟哥的Linux私房菜--基础篇>学习笔记 ubuntu默认的sh是连接到dash,而我们写shell脚本时使用的时bash.bash和dash在一些方面是不兼容的.因此执行同一 ...

  6. windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决

    windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决 一.发现问题 由于tomcat内存溢出,在wind ...

  7. mac 上python编译报错No module named MySQLdb

    mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...

  8. 调用python脚本报错/usr/bin/env: python : No such file or directory

    一.调用python脚本报错 /usr/bin/env: python: No such file or directory 二.解决方法 原因是在windows上编写的脚本,使用dos2unix对脚 ...

  9. apscheduler 执行报错No handlers could be found for logger "apscheduler.executors.default

    执行报错如下: No handlers could be found for logger "apscheduler.executors.default 解决: 加入日志,查看具体报错,载根 ...

随机推荐

  1. iOS限制输入表情(emoji),出现九宫格不能输入的解决方法

    在提交数据发送网络请求,由于用户输入了emoji表情,服务端返回系统异常,体验感很差.为了解决服务器不能验证emoji编码的问题,需要在本地进行emoji的输入控制(一般情况应该由服务器在数据库中添加 ...

  2. Xcode 8 修改项目名

    很麻烦,不想修改了 有个教程,贴一下. From: 大发写字的地方 Xcode8 修改包名(含cocopods)

  3. 有关linux中,<math.h>的调用方法

    h{font-weight:bold;color:green;font-size:105%} p{font-size:100%} linux下C语言程序中,若要用到math.h中的函数(如:sin() ...

  4. .NET实现CORS跨域

    1.NuGet:Install-Package Microsoft.AspNet.WebApi.Cors 2.Application_Start中增加(包含在#if DEBUG中):GlobalCon ...

  5. Jmeter用表格查看结果

    Sample#:编号类似id Start Time:开始时间 Thread Name:线程名称 Label:请求名称 Sample Time:取样时间ms Status:状态 Bytes:接受字节数 ...

  6. .NET 中 GetProcess 相关方法的性能

    .NET 的 Process 类中提供了查找进程的若干方法,其中部分方法还比较消耗性能.如果你试图优化查找进程相关方法的性能,可能本文分享的一些耗时数据可以作为参考.   性能比较 Process 类 ...

  7. C#中 this关键字 四种用法

    /// <summary> /// 主程序入口 /// </summary> /// <param name="args"></param ...

  8. ubuntu qq安装

    安装最新版qq2016 qq2012下载链接: https://pan.baidu.com/s/1miFVc04 密码: 3g9w 先解压到自己所在的目录,解压命令自己百度在这个目录下,有三个解压包, ...

  9. Linux 权限使用 777 真的好吗?

    Linux 权限使用 777 真的好吗? 开发环境当然不是问题,但是会造成一个习惯,到生产时也容易经常配置成 777. 777 权限可以让你的项目出现很大安全问题.1 linux 775和777权限有 ...

  10. Debian初识(选择最佳镜像发布站点加入source.list文件)

    选择最佳镜像发布站点加入source.list文件:netselect,netselect-apt “该将哪个Debian镜像发布站点加入source.list文件?”.有很多方法来选择镜像发布站点, ...