所以我有一個像這樣的文件夾結構。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任何地方,但是。我想自己運行它。編輯:無論我回復誰刪除了他們的評論。 –