覆盖范围:ImportError:无法导入名称配置

时间:2016-02-26 01:54:52

标签: python python-2.7 testing coverage.py

当我尝试运行此代码时,我得到:lib/python2.7/site-packages/tests/functional_tests/fixtures/__init__.py 在此文件的第32行:

import os
COV = None
if os.environ.get('FLASK_COVERAGE'):
    import coverage
    COV = coverage.coverage(branch=True, include='app/*')
    COV.start()

from flask.ext.script import Manager, Shell
from app import create_app, db
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)

@manager.command
def test(coverage=False):
    """Run the unit tests."""
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        import sys
        os.environ['FLASK_COVERAGE'] = '1'
        os.execvp(sys.executable, [sys.executable] + sys.argv)
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)
    if COV:
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'tmp/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        COV.erase()

if __name__ == '__main__':
    manager.run()

有关此错误原因的任何想法?

python coverage.py test

ERROR: tests.functional_tests.test_providers (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.functional_tests.test_providers
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/loader.py", line 252, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python2.7/unittest/loader.py", line 230, in _get_module_from_name
    __import__(name)
  File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/tests/functional_tests/__init__.py", line 1, in <module>
    from . import fixtures
  File "/home/vagrant/myproject/venv/local/lib/python2.7/site-packages/tests/functional_tests/fixtures/__init__.py", line 32, in <module>
    from tests.functional_tests import config
ImportError: cannot import name config


----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

错误日志:

[mainTableView setContentOffset: CGPointZero animated: YES];

0 个答案:

没有答案