AttributeError:对象没有属性“_type_equality_funcs”

2023-12-14

我的程序的 Unittest 模块实现出现以下错误

File "/usr/lib/python2.7/unittest/case.py", line 493, in _getAssertEqualityFunc
    asserter = self._type_equality_funcs.get(type(first))
AttributeError: 'Utility' object has no attribute '_type_equality_funcs'  

当我尝试创建一个公共类并尝试通过公共类实用程序测试函数执行时出现上述错误,但使用正常的 Unittest 类实现时没有出现错误。

下面是执行没有任何错误的程序的详细说明

class BaseTestCase(unittest.TestCase):

    def __init__(self, methodName='runTest', param=None):
        super(BaseTestCase, self).__init__(methodName)
        self.param = param

    @staticmethod
    def parametrize(testcase_klass, param=None):

        testloader = unittest.TestLoader()
        testnames = testloader.getTestCaseNames(testcase_klass)
        suite = unittest.TestSuite()
        for name in testnames:
            suite.addTest(testcase_klass(name, param=param))
        return suite

现在我继承基本测试用例类并调用测试用例..

     class salesgrowth_DevInt(BaseTestCase):
          def setUp(self):
                print "constructor"
                pwd = os.getcwd()

     def test4_refactoring(self,log):
             if (STATUS.lower() == "completed" or STATUS == "Actor : SUCCESS"):`enter code here`
                  self.assertEqual(os.stat(OUTPUT + '/tes1.txt').st_size, 0,
                 'employee count  is not matching with master data . Different  entries are in test1.txt\n')

到目前为止一切正常

现在像 salesgrowth_DevInt 测试用例一样,没有其他测试用例继承 BaseTestCase 并执行 test4_refactoring 测试用例(这里例如测试用例没有删除行),以避免代码重复 我创建了公共类实用程序,包括为所有测试用例提供服务的 test4_refactoring 函数,例如 salesgrowth_DevInt 。

下面是通用实用程序类代码

import sys
import json, sys, os, argparse, commands, time, string, filecmp
import unittest

class Utility(object):
    ''' common utility class for common test cases  operations'''

    def __init__(self):
        print "constructor"
        pwd = os.getcwd()
        print "Current working directlry %s\n" % pwd
        global scriptpath
        scriptpath = os.path.join(pwd, "src/Runner/")
        maxDiff = int(80)


     def test4_refactoring(self,STATUS,BASE,ANALYSIS_DIR,OUTPUT,log):
            print "common function"
            log.write('\n')
             if (STATUS.lower() == "completed" or STATUS == "Actor : SUCCESS"):
                  self.assertEqual(os.stat(OUTPUT + '/tes1.txt').st_size, 0,
                 'employee count  is not matching with master data . Different  entries are in test1.txt\n')




     but using utility code when i try to execute below statment
     self.assertEqual(os.stat(OUTPUT + '/tes1.txt').st_size, 0,
                 'employee count  is not matching with master data . Different  entries are in test1.txt\n') 


    getting below errors


Traceback (most recent call last):
  File "/src/testCases/salesgrowth_DevInt.py", line 96, in test4_refactoring
    utils_obj.test4_refactoring(self.STATUS,self.BASE,self.ANALYSIS_DIR,self.OUTPUT,log)
  File "/src/common/Utils.py", line 436, in test4_refactoring
    'employee count  is not matching with master data. Different entries are in test1.txt\n')
  File "/usr/lib/python2.7/unittest/case.py", line 512, in assertEqual
    assertion_func = self._getAssertEqualityFunc(first, second)
  File "/usr/lib/python2.7/unittest/case.py", line 493, in _getAssertEqualityFunc
    asserter = self._type_equality_funcs.get(type(first))
AttributeError: 'Utility' object has no attribute '_type_equality_funcs'




 Please let me know if any one has any pointers or suggestion for above issue and what is wrong in above implementation.

self.assertEqual仅适用于继承的类unittest.TestCase类,您的Utility类没有做。

我建议尝试把你的Utility下的方法BaseTestCase class.

给它一个不开头的名称test_,稍后调用这个新函数来验证您对许多其他函数的断言。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AttributeError:对象没有属性“_type_equality_funcs” 的相关文章

随机推荐

  • 在 .NET 运行时解析 JSON

    我想从 WebServer 得到一些响应 返回的数据如下所示 3014887 string1 string http num60 webservice com u3014887 b c9c0625b jpg 0 3061529 string
  • 在树结构上实现 IEnumerable

    基于这些人的工作 http dvanderboom wordpress com 2008 03 15 treet implementing a non binary tree in c http www matthidinger com a
  • Python 线程。如何锁定线程?

    我试图了解线程和并发的基础知识 我想要一个简单的情况 其中两个线程重复尝试访问一个共享资源 代码 import threading class Thread threading Thread def init self t args thr
  • 使用Scrapy抓取时无法在源代码中找到显示的数据

    我在 Windows Vista 64 位上使用 Python org 版本 2 7 64 位 我使用 Scrapy 和正则表达式的组合从以下页面中名为 DataStore Prime 的 Javascript 项目中提取信息 http w
  • 未终止的字符串文字/无效或意外的标记

    为什么我会 语法错误 未终止的字符串文字 in Firefox and 未捕获的语法错误 无效或意外的标记 in Chrome当我跑 document ready function function addJSBeforeEndBody c
  • 如何在一次 jQuery 调用中在两个文本之间切换?

    假设你有一个 click 称呼 你可以在里面写什么代码 click 调用 以便每次单击所选元素时 都会更改两个字符串之间的文本 我假设 toggle and text 会在这里发挥作用 尝试按照以下思路进行操作 element bind c
  • 同时播放两种声音

    有没有办法同时播放两种声音 我知道SoundPlayer无法做到这一点 我不能使用SoundEffect因为我相信它只是 XNA 的一部分 所需的两个声音将在未知且随机的时间被调用 声音播放后需要进行控制 即 声音必须能够在播放完毕之前停止
  • 在 Android 的导航栏顶部绘制位图

    在我的应用程序中 我需要在所有正在运行的应用程序之上绘制一个位图 我创建了一个不可见的视图 并覆盖在所有应用程序之上 使用此覆盖视图 我可以在给定位置绘制位图 但无法在导航栏顶部绘制位图 我使用了以下布局参数 WindowManager L
  • sphinx可以链接到不在根文档下面的目录中的文档吗?

    我正在使用 Sphinx 来记录一个非 Python 项目 我要分发 doc每个子模块中的文件夹 包含submodule name rst文件来记录该模块 然后 我想将这些文件吸收到主层次结构中 为整个设计创建规范 I e Project
  • 使用 itext 的 XML 工作器

    import java io FileOutputStream import java io StringReader import com itextpdf text Document import com itextpdf text P
  • 为什么 Thread.interrupt() 不能中断尝试获取锁的线程

    Thinking in Java 一书中写道 Thread interrupt 无法中断尝试获取同步锁的线程 我想知道为什么 阻塞操作只有在声明为抛出异常时才能被中断InterruptedException 显然 一个synchronize
  • Python Tkinter 两个按钮的一个回调函数

    我已经寻找这个问题的答案很长时间了 但仍然没有找到任何东西 我正在使用 Tkinter 创建一个 GUI 并且我有两个按钮 除了从不同的小部件接收信息之外 它们基本上执行相同的操作 一个按钮用于条目小部件 另一个按钮用于列表框小部件 这两个
  • “SELECT”语句中的“IF” - 根据列值选择输出值

    SELECT id amount FROM report I need amount to be amount if report type P and amount if report type N 如何将其添加到上面的查询中 SELEC
  • Python cx_Oracle 绑定变量

    我是一个Python新手 我在使用绑定变量时遇到了麻烦 如果我执行下面的代码 一切都会正常 bind var ciao sql select from sometable where somefield bind cur prepare s
  • 多重登录选项的用例

    我有一个用例 用户可以通过普通登录以及社交登录 例如 Twitter Google Facebook 登录 我如下绘制用例 但不确定它是否正确 登录账号 扩展 gt 正常登录 扩展 gt Twitter 登录 扩展 gt 谷歌登录 扩展 g
  • 登录后如何在firebase中上传用户个人资料图片?

    我将个人资料图片上传到 Firebase Storage 包含用户信息的数据库屏幕截图然后我获取图像 URL 并将其存储到 Firebase 实时数据库中 当我将 imagurl 存储到 Firebase 实时数据库中的特定用户时 我看到我
  • numpy改变元素匹配条件

    对于两个 numpy 数组 a b a 1 2 3 b 4 5 6 我想将a的x a a lt 2 5 b 希望成为a 4 5 3 但这会出错 Traceback most recent call last File
  • importlib.reload 不会重新加载以编程方式生成的文件

    第二个断言失败 表明导入库 重新加载默默地无法重新加载修改后的模块 任何人都可以解释为什么吗 import os import sys import tempfile import importlib Create some module
  • 用于查找树中支配集的多项式时间算法

    设 G V E 为无向图 G 中节点的子集 S V 称为 支配集 如果对于所有 v V 我们有 v S 或存在某个节点 u S 使得 u v E 换句话说 每个V S 中的节点通过边连接到 S 中的某个节点 给定 V 节点上的非负权重 w
  • AttributeError:对象没有属性“_type_equality_funcs”

    我的程序的 Unittest 模块实现出现以下错误 File usr lib python2 7 unittest case py line 493 in getAssertEqualityFunc asserter self type e