erhalte ich folgende Fehler mit Unittest-Modul für mein Programm implementierenAttribute: Objekt hat kein Attribut ‚_type_equality_funcs‘
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'
, wenn ich versuche, eine gemeinsame Klasse zu erstellen und versuchen, durch gemeinsame Klasse Dienstprogramm Testfunktionen auszuführen über Fehler erhalten, aber mit der normalen Implementierung der Unittest-Klasse wurde kein Fehler angezeigt.
unten ist eine detaillierte Erläuterung des Programms, das
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
Jetzt
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')
bis zu diesem alles funktioniert ok
jetzt .. Ich bin vererben BaseTestCase Klasse und ruft Testfälle ohne Fehler ausgeführt wird Wie bei salesgrowth_DevInt - Testfällen gibt es keine anderen Testfälle, die BaseTestCase erben und test4_refactoring - Testfälle ausführen (hier für exa mple-Testfälle keine Zeilen entfernt), um Doppelung von Code zu vermeiden Ich habe gemeinsame Klasse erstellt Dienstprogramm enthält test4_refactoring-Funktion für alle Testfälle wie Salesgrowth_DevInt.
unten ist Gemeinsame Utility-Klasse Code
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.
Große Frage, ich habe das gleiche Problem, und Sie haben es für mich getan, danke dafür, dass Stackoverflow hilft :) – Nilesh