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

时间:2021-10-13 08:07:20

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'的更多相关文章

  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. 利用Microsoft.Practices.Unity的拦截技术,实现.NET中的AOP

    1.记住这个单词的意思:Interception(拦截) 2.首先说一下原理和背景 原理:所谓的AOP就是面向切面编程,这里不多说,百度搜索. 目的:个人认为是为了解耦,部分代码跟业务代码分离,业务代 ...

  2. oracle存储过程截取字符串

    declare CURSOR l_c IS select classid from cjt_class; Begin FOR i IN l_c LOOP update cjt_class t set ...

  3. ChartDirector应用笔记(二)

    关于Simple Bar Chart Simple bar chart是XYChart大类中的Bar chart类型中的最简单的例子.Bar chart的表现形式简单直观,在数据量较少.数据维度简单等 ...

  4. Android.mk学习 笔记

    感谢: 原创作品 转载请注明出处:http://www.cnblogs.com/langlang/ 作者email: dayhappyhappy@163.com LOCAL_PATH := $(cal ...

  5. Spark 1.4连接mysql诡异的问题及解决

    在spark-default.conf文件中明明配置了mysql的数据源连接 随后启动spark-shell 执行如下测试代码: import org.apache.spark.{SparkConte ...

  6. JGroups 入门实践(转)

    前言 JGroups是一个开源的纯java编写的可靠的群组通讯工具.其工作模式基于IP多播,但可以在可靠性和群组成员管理上进行扩展.其结构上设计灵活,提供了一种灵活兼容多种协议的协议栈. JGroup ...

  7. AspNetPager常用属性及一些样式

    AlwaysShow 总是显示分页控件,即使要分页的数据只有一页 AlwaysShowFirsLastPageNumbr 是否总是显示第一页和最后一页数字页索引按钮 BackImageUrl 面板的背 ...

  8. C语言博客作业3--函数

    C语言博客作业3--函数 1.本章学习总结 1.1思维导图 请以思维导图总结本周的学习内容,如下图所示: 1.2本章学习体会及代码量学习体会 1.2.1学习体会 描述本周学习感受,也可以在这里提出你不 ...

  9. dell T130服务器加内存

    需求:客户一台dell T130塔式服务器,由于本机只有一条8G内存,系统运行比较慢,需要再增加一条8G内存. 增加过程:第一次增加时由于没有注意机器上内存频率是2133的,所以新增加的一条2400频 ...

  10. (3)HomeAssistant 连接MQTT

    整体说明 1 自己在阿里云上搭建MQTT服务器 2 自己笔记本电脑windos10搭建HASS,配置参数连接阿里云服务器 3 手机下载MQTT调试助手,当测试端 4手机当终端---阿里云MQTT--- ...