场景:请求获取验证码模块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. PHP循环嵌套例子

    循环嵌套1.实现如下效果:第一行第二行第三行第四行第五行1 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 52.实现如下效果图:第一行第二行第三行第四行第五行1 2 3 4 56 ...

  2. Weinre(pc调试手机页面)

         Weinre是一款基于Web Inspector(Webkit)的远程调试工具,借助于网络,可以在PC上直接调试运行在移动设备上的远程页面,中文意思是远程Web检查器,有了Weinre,在P ...

  3. idea和pycharm激活方法

    idea和pycharm是jetbrains出品的很火的开发辅助工具,不过目前来说是收费的,对于囊中羞涩的同学来说还是比较困难的 我写这篇博客只是为了方便新手使用,推进开发进程,但希望大家在合适的情况 ...

  4. 程序设计入门-C语言基础知识-翁恺-第七周:指针与字符串-详细笔记(七)

    目录 第七周:指针与字符串 7.1 指针初步 7.2 字符类型 7.3 字符串 7.3 课后练习 第七周:指针与字符串 7.1 指针初步 sizeof 是一个运算符,给出某个类型或变量在内存中所占据的 ...

  5. 2017年 ACM Journal Latex templates 新模板生成 acmart.cls 文件

    假定你的文稿在:/user/acmart-master那么cd /user/acmart-masterlatex acmart.ins最后可得到acmart.cls.

  6. flask第十四篇——重定向

    我们都知道京东的url是www.jd.com,但是当你输入www.jingdong.com时候,你会发现地址自动跳转到了www.jd.com,这种技术手段就叫做重定向. 重定向分为永久重定向和临时重定 ...

  7. 《selenium2 python 自动化测试实战》(19)——webdriver错误截图

    webdriver 提供错误截图函数 get_screenshot_as_file(),可以帮助我们跟踪 bug,在脚本无法继续执行时候, get_screenshot_as_file()函数将截取当 ...

  8. Web API的发布问题

    配置“ISAPI 和 CGI 限制”的4.0版本设置为允许,要不然出现“由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面.”的错误. “An error has ...

  9. 【DUBBO】dubbo的Cluster接口

    Directory中的多个Invoker伪装成一个Invoker, 对上层透明,包含集群的容错机制 Cluster可以看做是工厂类, 将目录directory下的invoker合并成一个统一的Invo ...

  10. flash无法导入mp3文件

    用全能音频转换通转换下,一切采用默认即可,点击下载地址 这个软件真心好用. 把mp3拖入其中,点击批量转换,参数默认,即可.