源代码:

#!usr/bin/python3
# -*- coding:utf-8 -*-
# @Time: 2018/12/17 下午2:07
# @File: do_excel.py
# @Software: PyCharm
import unittest
from api_auto.common.do_excel import DoExcel
from api_auto.common.do_excel import project_path
from api_auto.common.request import Request
import json
from ddt import ddt, data do_excel = DoExcel(project_path.CASE_FILE)
cases = do_excel.get_cases("login")
# 测试登录
@ddt
class TestLogin(unittest.TestCase): def setUp(self):
pass def tearDown(self):
pass @data(*cases)
def test_login(self, case):
data_dict = json.loads(case.data)
response = Request(method=case.method, url=case.url, data=data_dict)
print("statue_code:", response.get_statue_code())
try:
self.assertEqual(case.expected, response.get_text())
except AssertionError as e:
print("断言错误")
raise e

原因:运行的时候光标的位置放在 test_login 方法里面了,加了ddt后,运行时要先识别装饰的类,将光标放在某一个方法后面的话,测试用例只会执行当前的方法,ddt识别不到类,就会报错,

将光标放到外面,则运行通过,或者加main方法,再运行,也不会报错

其他可能原因,setUp 或者 tearDown 拼写错误也可能报此错误

ddt运行报错AttributeError: type object 'TestLogin' has no attribute 'test_login'的更多相关文章

  1. ddt运行测试方法时报错AttributeError: type object 'TestHttpRq' has no attribute 'test_http_rq_login'

    import unittest import ddt #装饰器 from ddt import ddt,data,unpack #导入ddt中的各个模块 from homework.unittest_ ...

  2. Python - celery 相关报错 - AttributeError: type object '_multiprocessing.win32' has no attribute 'WAIT_OBJECT_0'

    报错场景 执行   celery worker -A tasks -l INFO  打开 worker 的时候报错无法进行 报错解决 Celery 的版本过高, 进行降级处理即可 pip instal ...

  3. dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'

    有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...

  4. py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】

    问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图  或者  解决方法:   将”driver ...

  5. AttributeError type object 'deprecated' has no attribute 'ROCKY'

    AttributeError type object 'deprecated' has no attribute 'ROCKY' 在使用kolla安装docker的时候遇到了AttributeErro ...

  6. AttributeError: type object 'testClass' has no attribute 'testMothod'

    点击"Unittest for test_post_API.testClass"按钮,点击”Edit configuration...“,弹出对话框Run/Debug config ...

  7. 运行报错:'_TestResult' object has no attribute 'outputBuffer'

    一.运行main函数,未生成测试报告,报错:'_TestResult' object has no attribute 'outputBuffer' 解决方式: 1.在HTMLTestReportCN ...

  8. JAVA运行报错 [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;

    执行 String[] rwords = (String[]) list.toArray(); 报错[Ljava.lang.Object; cannot be cast to [Ljava.lang. ...

  9. 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"

    最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...

随机推荐

  1. linux运维/自动化开发__目录

    服务器软件安装 nginx apache php mysql oracle tomcat memcached mongodb sqlserver 常用pc端工具安装使用 Xshell         ...

  2. Torch-RNN运行过程中的坑 [2](Lua的string sub函数,读取中文失败,乱码?)

    0.踩坑背景 仍然是torch-rnn/LanguageModel.lua文件中的一些问题,仍然是这个狗血的LM:encode_string函数: function LM:encode_string( ...

  3. 修改原型给数组对象添加forEach

    Array.prototype.forEach = function (callback, context) { for (var i = 0; i < this.length; i++) { ...

  4. ajax利用html5新特性带进度条上传文件

    http://blog.csdn.net/pkgray/article/details/27591283 http://www.matlus.com/html5-file-upload-with-pr ...

  5. <转载> C++笔试、面试笔记

    这些东西有点烦,有点无聊.如果要去C++面试就看看吧.几年前网上搜索的.刚才看到,就整理一下,里面有些被我改了,感觉之前说的不对或不完善. 1.求下面函数的返回值( 微软) int func(x)  ...

  6. XShell上传和下载

    工具:XShell 本地环境:win7操作系统 远程服务器环境:linux系统 1.将本地的文件上传到远程服务器上 可以使用rz命令 rz命令详细使用方法可以在xshell中输入:rz -h 2.将远 ...

  7. Kubernetes之kubectl常用命令

    最近项目有用到Kubernetes作集群配置,所以学习下相关命令,记录下以备下次使用... kubectl help 显示具体的用法 kubectl controls the Kubernetes c ...

  8. 170120、java 如何在pdf中生成表格

    1.目标 在pdf中生成一个可变表头的表格,并向其中填充数据.通过泛型动态的生成表头,通过反射动态获取实体类(我这里是User)的get方法动态获得数据,从而达到动态生成表格. 每天生成一个文件夹存储 ...

  9. POJ 2773 Happy 2006(容斥原理+二分)

    Happy 2006 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10827   Accepted: 3764 Descr ...

  10. java反射——字段

    大家都知道反射技术在Java里面时非常重要的一个技术点,因为Java好多框架的编写都是基于反射的,别的不多说,spring框架里面的IOC就是基于反射实现.那么什么是反射呢?JAVA反射机制是在运行状 ...