2017-09-20 46 views
1

爲什麼測試覆蓋率還包括覆蓋率報告中的燒瓶相關性。爲什麼測試覆蓋率還包括覆蓋率報告中的燒瓶相關性

我運行下面的命令:coverage run tests/test_basic.py 然後coverage report -m

請看看這個:large_report_file_saved_to_pastebin

我只希望看到這一點:

src/__init__.py    11  0 100% 
src/appforms.py    17  0 100% 
src/config.py    20  0 100% 
src/controller.py   67  38 43% 35-42, 47-61, 66-75, 80, 85, 90, 95, 100, 105, 110, 115, 120 
src/dataStruct.py    1  0 100% 
src/model.py    111  57 49% 30-80, 88, 104, 111-118, 133-137, 159-169, 178-179, 184-187 
src/timeUtils.py    41  33 20% 27-34, 52-66, 72-79, 87-90 
src/utils.py     80  53 34% 21, 29, 34-43, 49-60, 71-75, 79-82, 90, 93, 98, 101, 109-114, 117-126 
src/views.py    126  60 52% 41, 44-63, 75, 105-156, 172, 177, 193-194, 205-220, 227 
src/visitorTracking.py  20  4 80% 37-45 
tests/test_basic.py   36  0 100% 
------------------------------------------------------------------------------------------------- 

我只寫了一些基本測試並希望得到報道:

import os 
import sys 
import unittest 
import stubout 
import mox 
sys.path.insert(0, os.getcwd()) 


from src import app 
from src import utils as _utils 
from src.model import db 
from src import timeUtils as _timeUtils 


mockData = {u'city': 
{ 
u'country': u'IN', 
u'population': 0, 
u'id': 1259775, 
u'coord': {u'lat': 31.0292, 
u'lon': 75.7842}, 
u'name': u'Phillaur'}, 
u'message': 4.410899, 
u'list': [{u'clouds': 0, 
u'temp': {u'min': 23.68, 
u'max': 34.04, 
u'eve': 32.79, 
u'morn': 34.04, 
u'night': 23.68, 
u'day': 34.04}, 
u'humidity': 53, 
u'pressure': 988.76, 
u'weather': [{u'main': u'Clear', 
u'id': 800, 
u'icon': u'01d', 
u'description': u'sky is clear'}], 
u'dt': 1505887200, 
u'speed': 0.84, 
u'deg': 233}], 
u'cod': u'200', 
u'cnt': 1 
} 

class BasicTests(unittest.TestCase): 
    def setUp(self): 
     app.config['TESTING'] = True 
     app.config['WTF_CSRF_ENABLED'] = False 
     app.config['DEBUG'] = False 
     self.app = app.test_client() 

    def test_index_page(self): 
     self.mox = mox.Mox() 
     self.mox.StubOutWithMock(_utils, "getClientIp") 
     _utils.getClientIp().AndReturn(["127.0.0.1"]) 
     response = self.app.get('/', follow_redirects=True) 
     self.addCleanup(self.mox.UnsetStubs) 
     self.assertEquals(response.status_code, 200) 

    def test_index_page_with_city(self): 
     self.mox = mox.Mox() 
     self.mox.StubOutWithMock(_utils, "getClientIp") 
     _utils.getClientIp().AndReturn(["127.0.0.1"]) 

     self.mox.StubOutWithMock(_utils, "getWeatherURL") 
     _utils.getWeatherURL(u"Phillaur", count=u'1').AndReturn('/some/fake/URL') 

     self.mox.ReplayAll() 
     response = self.app.get('/?searchCity=Phillaur&count=1', follow_redirects=True) 
     self.assertEquals(response.status_code, 200) 
     self.mox.VerifyAll() 

if __name__ == "__main__": 
    unittest.main() 

任何幫助將不勝感激。

+0

HTTPS:// stackoverflow.com/questions/34728734/python-unit-test-coverage – Anup

+0

感謝Anup(y)。鏈接的答案非常接近 –

回答

0

對於這樣的項目的目錄結構:

|____src 
| |______init__.py 
| |____appforms.py 
| |____config.py 
| |____controller.py 
| |____dataStruct.py 
| |____issLocation.py 
| |____model.py 
| |____timeUtils.py 
| |____utils.py 
| |____views.py 
| |____visitorTracking.py 
|____static 
| |____bootstrap 
| | |____bootstrap-responsive.css 
| | |____bootstrap-responsive.min.css 
| | |____bootstrap.css 
| | |____bootstrap.js 
| | |____bootstrap.min.css 
| | |____bootstrap.min.js 
| |____favicon.ico 
| |____img 
| | |____.DS_Store 
| | |____divbg.jpg 
| | |____dr-manhattan-icon.png 
| | |____glyphicons-halflings.png 
| | |____weather 
| | | |____clear-night.png 
| | | |____clouds.png 
| | | |____cloudy-night-icon.png 
| | | |____cloudy-night.png 
| | | |____cloudy.png 
| | | |____Rain-Night.png 
| | | |____rain.ico 
| | | |____rain.png 
| | | |____rainy_thunder_cloudy.png 
| | | |____Snow.png 
| | | |____sun-cloudy-thunder.png 
| | | |____sunny.png 
| |____js 
| | |____jquery.min.js 
| | |____main.js 
| | |____testingJS.htm 
| |____main.css 
| |____Open_Sans-300_400_600_font.css 
| |____style.css 
|____templates 
| |____display_weather_icon.html 
| |____form.html 
| |____head.html 
| |____index.html 
| |____landing.html 
| |____layout.html 
| |____map.html 
| |____newMessage.html 
| |____thankyou.html 
|____terminal.glue 
|____tests 
| |______init__.py 
| |____test_basic.py 

我第一次運行下面線測試:

$ coverage run --source src/ -m unittest discover -s tests/

然後跑到照例:$ coverage report -m