2017-04-11 5 views
0

은 내가 이렇게 보이는 장고 응용 프로그램의 클래스를 기반으로보기 있습니다범위가 Djangos views.py에 아무 것도보고하지 않는 이유는 무엇입니까?

class CBView(View): 

    def get(self, request, client, *args, **kwargs): 
     output1 = self.method1(argument1) 
     output2 = self.method2(argument2) 
     # Rest of the method implementation 
     ... 

     return response 

    def method1(self, argument1): 
     # Implementation 
     ... 

     return output1 

    def method2(self, argument2): 
     # Implementation 
     ... 

     return output2 

을 그리고 나는 '쉽게'클래스 메소드, 즉 method1method2에 대한 단위 테스트를 작성하려고 해요. 테스트는 다음과 같습니다 : 그 후

class TestCBView(TestCase): 

    def setUp(self): 
     self.view = CBView() 

    def test_method1(self): 
     # Testing that output1 is as expected 
     ... 
     output1 = self.view.method1(argument1) 
     ... 
     self.assertEquals(output1, expected_output1) 

    def test_method2(self): 
     # Testing that output2 is as expected 
     ... 
     output2 = self.view.method2(argument2) 
     ... 
     self.assertEquals(output2, expected_output2) 

를, 나는 실행

성공적으로 모든 테스트를 실행
coverage run ./manage.py test django_app.tests.test_cbview 

, 그때 내가 실행하려고 :

coverage report -m django_app/views.py 

를 내가 얻을 :

Name Stmts Miss Cover Missing 
------------------------------------- 
No data to report. 

나는 뭔가를하고있다. wro 응?

저는 Coverage.py, 버전 4.0.3, 장고 1.8.15 및 Python 2.7.13을 사용하고 있습니다.

+0

여기를 참조하십시오 : http://stackoverflow.com/questions/7051070/why-doesnt-coverage-py-properly-measure-djangos-runserver-command –

답변

0

coverage으로 테스트를 실행하면 .coverage 파일이 개인용 형식이며 직접 읽을 수 없습니다. 이 파일에는 본체 또는 coverage html의 html 형식으로 보고서를 표시하는 데 사용되는 원시 보고서가 들어 있습니다. 따라서 검사가 정상적으로 실행되면 coverage run ./manage.py test django_app.tests.test_cbview 명령을 실행 한 디렉토리에 .coverage 파일이 있어야하고 해당 디렉토리 아래에 있으면 coverage report ...을 치고 작동해야합니다.

+0

'django_app/tests/test_cbview.py '경로가 '.coverage' 파일 :( – Foryah

+0

테스트를 실행 한 후 문제가되지 않습니다. 테스트에서 '.coverage'를 찾아 위치로 이동하여 'coverage report -m path_to_your_test'를 실행하십시오. 당신의 경우에는 ' .coverage '를'manage.py '와 같은 디렉토리에 저장합니다. –

+0

'.coverage' 파일을 발견 했으므로 vim으로 파일을 열었습니다 (예, 예, 알고 있습니다. 나는 그렇게하지 않아야합니다 : D). 그리고 경로를 검색했습니다 테스트 ('django_app/tests/test_cbview.py')와 검색 결과가 비어 있습니다 ... – Foryah