ddt运行报错AttributeError: type object 'TestLogin' has no attribute 'test_login'

源代码:
#!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'的更多相关文章
- 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_ ...
- Python - celery 相关报错 - AttributeError: type object '_multiprocessing.win32' has no attribute 'WAIT_OBJECT_0'
报错场景 执行 celery worker -A tasks -l INFO 打开 worker 的时候报错无法进行 报错解决 Celery 的版本过高, 进行降级处理即可 pip instal ...
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- AttributeError type object 'deprecated' has no attribute 'ROCKY'
AttributeError type object 'deprecated' has no attribute 'ROCKY' 在使用kolla安装docker的时候遇到了AttributeErro ...
- AttributeError: type object 'testClass' has no attribute 'testMothod'
点击"Unittest for test_post_API.testClass"按钮,点击”Edit configuration...“,弹出对话框Run/Debug config ...
- 运行报错:'_TestResult' object has no attribute 'outputBuffer'
一.运行main函数,未生成测试报告,报错:'_TestResult' object has no attribute 'outputBuffer' 解决方式: 1.在HTMLTestReportCN ...
- 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. ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
随机推荐
- (转)数据库ACID特性
转自:http://blog.csdn.net/shuaihj/article/details/14163713 隔离级别实现原理:http://www.cnblogs.com/wrencai/p/5 ...
- PatternSyntaxException:Syntax error in regexp pattern
Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1: ...
- manacher算法处理最长的回文子串(二)
在上篇<manacher算法处理最长的回文子串(一)>解释了manacher算法的原理,接着给该算法,该程序在leetcode的最长回文子串中通过.首先manacher算法维护3个变量.一 ...
- js如何去除多个cookie?
转自:https://zhidao.baidu.com/question/211006012.html :1:设置cookie 最简单的就是:document.cookie="user=aa ...
- 160722、Javascript函数节流
最近在做网页的时候有个需求,就是浏览器窗口改变的时候需要改一些页面元素大小,于是乎很自然的想到了window的resize事件,于是乎我是这么写的 <!DOCTYPE html> < ...
- SQL server-自增主键
1.CREATE TABLE 表名( 字段名 [int] IDENTITY (1, 1) NOT NULL , //--(seed = 1,incre ...
- delphi--自带控件(Tcheckbox、TComBobox、TpageControl、TDBGrid,TScrollBox,TEdit)
一.TCheckBox 使CheckBox选中CheckBox1.Checked := True;选择发生变化 ,OnClick事件if CheckBox1.Checked thenbegin //. ...
- Storm-源码分析-Topology Submit-Task
mk-task, 比较简单, 因为task只是概念上的结构, 不象其他worker, executor都需要创建进程或线程 所以其核心其实就是mk-task-data, 1. 创建TopologyCo ...
- centos7开机启动tomcat7
1.进入tomcat/bin vi setenv.sh (原来没有这个文件,需要创建出来) 添加 #add tomcat pid CATALINA_PID="$CATALINA_B ...
- java maven项目打包
使用IDEA打包,首先调出来maven projects窗口: 菜单栏Help->Find Action(Ctrl+Shift+A),输入Maven projects https://blog. ...