2016-08-06 2 views
-1

클래스 내의 함수에 대한 단위 테스트를 작성하려고하는데 약간 문제가 있습니다. 수입업자 기능을 수업으로 옮기기 전에이 시험이 효과적이었습니다. 그러나, 지금 나는 TypeError: grab_column_locations missing 1 required positional argument: 'sheet'를 얻는다. 가져 오기 기능 자체가 올바르게 구문 분석되어 sheet이고 프로그램을 실행할 때 제대로 작동하지만 테스트 할 때 제대로 작동하지 않습니다.함수를 클래스로 옮긴 후 단위 테스트가 실패했습니다.

형식 오류가 수입 함수를 의미 라인은 다음과 같습니다 실패한 것

columns = self.grab_column_locations(sheet) 

테스트는 다음과 같습니다

from unittest import TestCase 

from gtt import GTT 


class TestGTT(TestCase): 

    def test_importer(self): 
     """ 
     Test import of valid xlsx file 
     :return: 
     """ 

     file_list = ['testData_1.xls'] 

     # Run Test 1 
     importer_results = GTT.importer(GTT, file_list) 
     assert importer_results[0] == True 

그래서 본질적으로, 테스트에서 실행할 때, importer은 통과되지 sheet ~ grab_column_locations. 이것은 두 함수를 모두 하나의 클래스로 옮겨 놓았을 때부터 시작되었습니다. 어떻게 든 부러 졌던 걸 압니다.하지만 뭐라 구요?

+0

디렉토리 구조는 어떻습니까? 또한 grab_column_locations 함수는 어떻게 생겼을 까? – Seekheart

답변

0

오류 메시지가이 말한다 :

TypeError: grab_column_locations missing 1 required positional argument: 'sheet' 

함수 서명이 같은이 소리 :

def grab_column_locations(self, sheet): 

당신은 경우이 기능을 소유하는 클래스의에서 호출하지 있습니까?

Foo.grab_column_locations(sheet) 

때 당신이 정말로해야 :

class Foo: 
    def grab_column_locations(self, sheet): 
     ... 

오류 메시지가 나에게 다음과 같이 함수를 호출하고 있다고 생각한다 : 함수가 클래스 Foo에 속하는 경우입니다

전화 :

foo = Foo() 
foo.grab_column_locations(sheet) 

다음과 같이

class Foo: 
    @classmethod 
    def grab_column_locations(self, sheet): 
     ... 

그런 다음 당신이 그것을 호출 할 수 있습니다 : 당신이 예를에 바인딩하지 않으려면 에드는 클래스 방법으로,

Foo.grab_column_locations(sheet) 

을하지만, 어쨌든이다 당신이 많은 세부 사항을주지 않았기 때문에 추측.

관련 문제