0

I have a simple flask blueprint application with the following folder structure.

.
├── backend
│   ├── app.py
│   ├── __init__.py
│   └── routes
│       ├── index.py
│       └── __init__.py
└── test
    ├── __init__.py
    └── test_index.py

index.py

from flask import Blueprint
index_blueprint = Blueprint('index', __name__)

@index_blueprint.route("/")
def index():
    return "Hello"

app.py

from flask import Flask
from routes.index import index_blueprint

app = Flask(__name__)
app.register_blueprint(index_blueprint)

if __name__ == "__main__":
    app.run(debug=True)

The application is working fine but running pytest gives me the following error. I am confused why am I getting this error.

Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_index.py:5: in <module>
    from backend.app import app
../backend/app.py:6: in <module>
    from routes.index import index_blueprint
E   ImportError: No module named 'routes'
Anjali A
  • 719
  • 9
  • 15

0 Answers0