2017-02-09 1 views
0

최근에 코를 nose2로 변경했는데 많은 테스트 코드가 깨져있는 것처럼 보입니다. 일부 nose2 내 초기화 변수로하지만,테스트 클래스에서 __init__ 변수를 찾을 수 없습니까?

mirror_index = mirror_matrix.index(self.mir_axis) 
AttributeError: 'TestConvert' object has no attribute 'mir_axis' 

이 코와 함께 작동하는 데 사용 : 특히 한 가지 내가 "self.mir_axis"내 테스트 클래스에 넣어 초기화하기 변수입니다이 오류를주는 이유가 더 이상 등록되지 않습니다. 내가 여기서 뭔가를 놓치고 있니? 파이썬 2.7.3을 사용하여, 그리고 IDE로 이클립스 btw.

from nose2.compat import unittest 
from nose2.tools import params 
from nose2 import session 
from nose2.events import ReportTestEvent 
from nose2.plugins import testid 
from nose2.tests._common import (FakeStartTestEvent, FakeLoadFromNameEvent, 
           FakeLoadFromNamesEvent, TestCase)# 
# Import maya modules 
import maya.cmds as mc 
# Absolute imports of other modules 
from neo_autorig.scripts.basic import name 
from neo_autorig.scripts.basic import utils 

# Test class for converting strings 
class TestConvert(TestCase): 
    counter = 0 # counter to cycle through mir_axes 

    def _init__(self): 
     mir_axes = ['xy', '-xy', 'yz', '-yz'] # different axes to be applied 
     self.mir_axis = mir_axes[self.__class__.counter] 
     self.__class__.counter += 1 # increase counter when run 
     if self.__class__.counter > 3: 
      self.__class__.counter = 0 # if counter reaches max, reset 
     self.utils = utils.Utils(self.mir_axis, False) # pass module variables 

    def setUp(self): # set up maya scene 
     side_indicator_l = mc.spaceLocator(n='side_indicator_left')[0] 
     side_indicator_r = mc.spaceLocator(n='side_indicator_right')[0] 
     mirror_matrix = ['xy', '-xy', 'yz', '-yz'] 
     trans_matrix = ['tz', 'tz', 'tx', 'tx'] 
     side_matrix = [1, -1, 1, -1] 
     mirror_index = mirror_matrix.index(self.mir_axis) 
     mc.setAttr(side_indicator_l+'.'+trans_matrix[mirror_index], side_matrix[mirror_index]) 
     mc.setAttr(side_indicator_r+'.'+trans_matrix[mirror_index], side_matrix[mirror_index]*-1) 

    def tearDown(self): # delete everything after 
     mc.delete('side_indicator_left', 'side_indicator_right') 

    def test_prefix_name_side_type(self): # test string 
      nc = name.Name('prefix_name_side_type') 
      existing = nc.get_scenenames('transform') 
      self.assertEqual(nc.convert('test', 'empty', self.utils.find_side('side_indicator_left'), 
       'object', existing), 'test_empty_l_object') 
      self.assertEqual(nc.convert('test', 'empty', self.utils.find_side('side_indicator_right'), 
       'object', existing), 'test_empty_r_object') 

# run if script is run from inside module 
if __name__ == '__main__': 
    import nose2 
    nose2.main() 

답변

1

난 당신이 게시 된 조각 두 가지 문제를 참조하십시오

첫 번째는 def _init__(self): 밑줄 누락됩니다; 그것은 def __init__(self):

두 번째가 될 (그리고 오류의 원인이 될 것으로 보인다) _init__의 첫 번째 줄, mir_axes = ['xy', '-xy', ...는, self.mir_axes = ...

편집해야한다는 사실은해야

당신은 setUp를 사용해야합니다 에 관계없이 __init__ 대신 Ned BatchelderCoverage.py 명성에 따라. :)

+0

오, 그 코드를 다시 편집해야 nose2에 적합해야합니다. 이제 오류가 발생했습니다. 'TypeError : __init __()은 정확히 1 개의 인수 (주어진 2 개)' –

관련 문제