我有一個Django應用程序的一類基於觀點看起來是這樣的:爲什麼報道不會在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
和我想要編寫單元測試的「方便」類方法,即method1
和method2
。這些測試是這樣的:
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.
我在做些什麼嗎? ng?
我正在使用Coverage.py,版本4.0.3,Django 1.8.15和Python 2.7.13。
請參閱:http://stackoverflow.com/questions/7051070/why-doesnt-coverage-py-properly-measure-djangos-runserver-command –