为什么测试覆盖率在覆盖率报告中还包括了烧瓶依赖关系。

我运行以下命令: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()


任何帮助将不胜感激。

最佳答案

对于这样的项目目录结构:

|____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

关于python - 为什么测试覆盖率在覆盖率报告中还包括了 flask 依赖性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46324545/

10-12 21:27