I’m trying to creat an API using Python. In my app folder there are the folders: models, services, tests. In each folder (including app) there is an empty init.py
In my model folder there is Ad.py file.
In my services folder there is an AdService.py file.
This is part of the code in my AdService.py file:
from models.Ad import Ad
from models.SubCategory import SubCategory
from database import session
class AdService:
.
.
.
In my tests folder there is a file name AdServiceTest.py.
This is part of the code in my AdServiceTest.py file:
import unittest
from datetime import datetime
from app.models.Ad import Ad # Ensure the import path is correct
from app.services.AdService import AdService # Ensure the import path is correct
from app.database import (Base,engine,session) # Assuming Base and engine are defined in your database module
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy import create_engine
# Setup in-memory SQLite database for testing
DATABASE_URL = "XXXX"
engine = create_engine(DATABASE_URL)
Session = sessionmaker(bind=engine)
session = scoped_session(Session)
class AdServiceTest(unittest.TestCase):
.
.
.
When I run my AdServiceTest.py I get an error on the line: “from app.models.Ad import Ad” with the text: “ModuleNotFoundError: No module named ‘app'”.
I tried changing the prefix to just models.Ad or ..models.Ad and nothing worked.
What am I doing wrong?
Thank you in advance!