I am having a very hard time trying to set up a simple test.
My project structure is as follows:
project:
models:
__init__.py
user.py
constants.py
test:
test.py
I want to test user.py
py running test.py
.
user.py
from sqlalchemy import Column, Integer, String, Text
from sqlalchemy.orm import relationship
from .models.constants import *
from .models import Base
class User(Base):
__tablename__ = 'users'
uid = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String, nullable=False)
email = Column(String, nullable=False)
picPath = Column(String, unique=True)
description = Column(Text)
def __repr__(self):
return "<User(uid=%s, name=%s)>" %(self.uid, self.name)
test.py
from ..user import User, Group
def _TestUser():
TEST_DB_URI = "postgresql://project:password@localhost:5432/projectdbtest"
SessionMaker = sessionmaker()
engine = create_engine(TEST_DB_URI)
SessionMaker.configure(bind=engine)
session = SessionMaker()
user = User("test subject", "[email protected]", "~/testsubject.jpg", "I am a test subject")
session.add(user)
session.commit()
However, I am getting the following error when I run python3 -m test.py
:
SystemError: Parent module '' not loaded, cannot perform relative import
I think I might have to add the modules package to the python path?