ImportError:无法导入名称应用Flask python?

时间:2018-02-13 14:27:17

标签: python unit-testing flask

当我运行时,我正在为我的烧瓶API编写单元测试:

python -m unittest test

我明白了:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/unittest/__main__.py", line 12, in <module>
    main(module=None)
  File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/usr/lib/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/usr/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "test.py", line 19, in <module>
    from rosbag_deserializer_api import app
ImportError: cannot import name app

这是我的代码:

from flasgger import Swagger
from flask import Flask, jsonify, request
from flask_cors import CORS
import os
import sys
from unittest import TestCase

sys.path.append('../src/rr_rosbag_deserializer')
sys.path.append('../scripts')

from rosbag_deserializer_api import app
from rosbag_deserializer_core import RosbagUploader, RosbagStatus
from utils import ReturnCodes


class TestAPI(TestCase):

    def setUp(self):
         app['TESTING'] = True
         self.app = app.test_client()

    def test_deserializer(self):

        data = {
          "buffer": 5000,
          "es_addr": "http://localhost:8000/",
          "es_index": "change_thiss",
          "es_type": "rosbag",
          "json": "r.json",
          "name": "2018-01-31-15-02-20.bag"
        }
        response = self.app.post('/deserializer', json=data)
        self.assertEquals(response.status_code, 200)



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

我运行不正确吗?我的应用运行正常,我只是想写一些单元测试。我尝试添加__init__.py但是,它没有帮助。我听说圆形进口是一个问题,但我不知道这意味着什么。

0 个答案:

没有答案