1、每个接口用例为一个.py文件。内容如下:

getAdMakeMoneyList文件:
# coding=utf-8
import xlrd
import requests
import unittest
from time import ctime class getAdMakeMoneyList1(unittest.TestCase):
def setUp(self):
data=xlrd.open_workbook('D:\\test.xlsx')
self.table=data.sheets()[0]
self.nrows=self.table.nrows
self. url='http://**********'
self.header={'Content-Type' : 'application/xml','charset':'UTF-8'} def test_post(self):
for i in range(self.nrows):
postdata=self.table.cell(i,0).value
yqdata=self.table.cell(i,1).value
response=requests.post(self.url,data=postdata,headers=self.header)
# print response.text
# print yqdata
try:
self.assertIn(yqdata,response.text,msg=u'用例错误,与预期结果不一致')
except AssertionError,e:
print e.message def tearDown(self):
pass
另一文件此处不粘贴了 在单独的.py文件中调用,用来实现用例与执行进行分离,方便管理
具体执行如下:
import unittest
import getAdMakeMoneyList
from getAdQuestionList import getAdQuestionList1
from getAdMakeMoneyList import getAdMakeMoneyList1 class maintest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
quit() if __name__ == '__main__':
suite=unittest.TestSuite()
suite.addTest(getAdMakeMoneyList)
suite.addTest(getAdQuestionList)
unittest.TextTestRunner(verbosity=2).run(suite) 说明:必须使用from .py的文件中导入具体的用例(用例为classname(unittest.TestCase))import 用例的文件名
加载时,addTest内名字填模块名称或者具体测试的classname都可以
不使用from** import导入,总是提示找不到测试组件

整合多个py文件接口的unittest。suite执行方法的更多相关文章

  1. 解决pycharm运行py文件时只有unittest选项的方法

    有时候在编完脚本开始运行时,发现某个py脚本右键运行的选项不是run,二是run in unittest,试过很多方法都不能很好的去除,主要是因为脚本中含有test字符串,一种解决方法是将脚本中所有的 ...

  2. Python+request 登录接口reponse的返回值token跨py文件的传递《二》

    主要使用场景: 一般我们在进行接口测试时,依赖登录接口后reponse中的某些返回值,因此需要将login接口单独写一个py文件,另外的py文件均可调用login的reponse返回值使用.共用登录接 ...

  3. 把py文件打成exe

    使用pyinstaller: pyinstaller -F -w -i manage.ico demo.py -F:打包为单文件-w:Windows程序,不显示命令行窗口-i:是程序图标,demo.p ...

  4. 【Python学习】使用Pyinstaller将py文件导出为exe文件

    PyInstaller其实就是把python解析器和你自己的脚本打包成一个可执行的文件,但是它不是跨编译的,也就是说在Windows下用PyInstaller生成的exe只能运行在Windows下,在 ...

  5. python如何编译py文件生成pyc、pyo、pyd以及如何和C语言结合使用

    python执行py文件的流程 当我们执行一个py文件的时候,直接python xx.py即可,那么这个流程是怎么样的呢.先说明一下,python执行代码实际上是先打开文件然后执行里面的代码,所以文件 ...

  6. 执行py文件需要可执行权限吗?

    案例解析 这个问题描述起来有点违反直觉,要执行一个文件难道不应该需要可执行权限吗?让我们先来看一个例子: # module1.py def test(): print ('hello world!') ...

  7. pytest:conftest.py文件

    一.fixture scope 为session 级别是可以跨 .py模块调用的,也就是当我们有多个 .py文件的用例时,如果多个用例只需调用一次fixture,可以将scope='session', ...

  8. unittest模块使用方法

    unittest模块常用属性 1. unittest.TestCase类:所有的测试用例类继承的基类 定义一个测试用例类,需要继承TestCase,比如: class BaiduTest(unitte ...

  9. webService接口的py文件打包成exe

    (一)webService接口的py文件打包成exe,在python3.5版本.pyInstaller3.2版本.pywin32-219.win-amd64-py3.5版本打包时报错,原因可能是pyi ...

随机推荐

  1. CMD控制台下的JAVAC就是“不是内部或外部命令

    [Path] 添加 %JAVA_HOME%\bin [JAVA_HOME] D:\Program Files\Java\jdk1.7.0_02 [CLASSPATH] .;%JAVA_HOME%\li ...

  2. Django进阶Form篇

    一.django表单系统中,所有的表单类都作为django.forms.Form的之类创建,包括ModelForm 关于django的表单系统,主要分两种: 1.基于django.forms.Form ...

  3. 51nod 1119 组合数,逆元

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119 1119 机器人走方格 V2 基准时间限制:1 秒 空间限制:13 ...

  4. opensack-mitaka网络性能测试shaker

    一.项目介绍 Shaker项目是由Mirantis发起,专门针对OpenStack网络性能的测试工具.通过模拟不同的网络场景和heat模板,创建虚拟机,并在虚拟机里运行iperf.iperf3.net ...

  5. 29-THREE.JS 根据公式画形状

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  6. 【hive】函数大全

    数学函数 Return Type Name (Signature) Description DOUBLE round(DOUBLE a) Returns the rounded BIGINT valu ...

  7. [eShopOnContainers 学习系列] - 00 - 开发环境需求

    开发环境需求 https://github.com/dotnet-architecture/eShopOnContainers/wiki/00.-Dev-machine-requirements 我的 ...

  8. WeChat on Web 部分功能模拟实现

    Flask from flask import Flask,request,render_template,session,jsonify import time import requests im ...

  9. List列表按照对象进行排序

    在某些业务场景下需要根据list列表中对象的字段进行排序.今天就以实例说明: 实体类 public class Product { private int discount; // 省略getter/ ...

  10. c++指针初探

    业余时间准备重温一下c++,因为在阅读Android源码到native层的时候感觉有点吃力,只是在大学时候很不用心的学过c++,所以重温下以便打好一些编程基础知识,本篇就很简单的对c++的指针做初步的 ...