'Flaskr tutorial ModuleNotFoundError No module named Flaskr
I am going through the flask tutorial up to the Test Coverage section. And after finishing writing all the test files listed in the tutorial documentation I get the following error.
ImportError while loading conftest '/home/Desktop/flask_tutoriel/tests/conftest.py'.
tests/conftest.py:5: in <module>
from flaskr import create_app
E ModuleNotFoundError: No module named 'flaskr'
- Could you help me understand why this error? Because the module is as you can see in the project tree image.
Conftest.py
import os
import tempfile
import pytest
from flaskr import create_app
from flaskr.db import get_db, init_db
with open(os.path.join(os.path.dirname(__file__), 'data.sql'), 'rb') as f:
_data_sql = f.read().decode('utf8')
@pytest.fixture
def app():
db_fd, db_path = tempfile.mkstemp()
app = create_app({
'TESTING': True,
'DATABASE': db_path,
})
with app.app_context():
init_db()
get_db().executescript(_data_sql)
yield app
os.close(db_fd)
os.unlink(db_path)
@pytest.fixture
def client(app):
return app.test_client()
@pytest.fixture
def runner(app):
return app.test_cli_runner()
class AuthActions(object):
def __init__(self, client):
self._client = client
def login(self, username='test', password='test'):
return self._client.post(
'/auth/login',
data={'username': username, 'password': password}
)
def logout(self):
return self._client.get('/auth/logout')
@pytest.fixture
def auth(client):
return AuthActions(client)
Tree of the test folder
tests
├── conftest.py
├── data.sql
├── __pycache__
│ └── conftest.cpython-39-pytest-7.1.1.pyc
├── test_auth.py
├── test_blog.py
├── test_db.py
└── tests_factory.py
Solution 1:[1]
That means that you haven't installed the module. Try uninstalling the package using pip uninstall flaskr then re-installing it with pip install -e .
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | davidism |
| Solution 2 | thga |
