所以我有一个像这样的文件夹结构。ImportError:没有模块命名的应用程序 - 试图运行单元测试
└── myApp
├── app
│ ├── __init__.py
│ ├── core
│ ├── db.py
│ ├── schema.sql
│ ├── static
│ │ ├── fonts
│ │ ├── images
│ │ ├── js
│ │ └── resources
│ ├── templates
│ ├── tests
│ │ └── tests.py
│ ├── utils.py
│ ├── views.py
│ ├── con.py
├── config.py
├── manifest.json
├── run.py
├── deps
├── store
正如你可以看到我的tests.py在app/tests文件夹中。
app = Flask(__name__)
是初始化中声明的.py但每当我尝试运行我的测试我的文件夹(这是我从对myApp目录做像这样:Python应用程序/测试/ tests.py)我得到一个ImportError: No module named app
。
我不确定这个信息是否相关,运行应用程序我通常运行run.py其中有app.run(debug = True, host='0.0.0.0')
里面。
感谢。
tests.py:
import os
import unittest
from app import app
class TestCase(unittest.TestCase):
def setUp(self):
self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
self.app = app.test_client()
def tearDown(self):
os.unlink(app.config['DATABASE'])
def test_empty_db(self):
rv = self.app.get('/index')
assert b'No entries here so far' in rv.data
if __name__ == "__main__":
unittest.main()
我不想导入tests.py任何地方,但是。我想自己运行它。编辑:无论我回复谁删除了他们的评论。 –