Quite new to python (using v3.11). I am trying to import something from another directory. I tried several different ways and the only way i was able to make it work is by adding ABSOLUTE path using sys.path.insert, which is obviously not correct. I suspect it is because im attempting to test class with factory method and I feel like i missed something.
This is what i have:
└── /project
├── /src
│ ├── /services
│ │ └── service1.py
│ │ class DataService:
│ │ def write_data(self,data,location):
│ └── containers.py
│ from dependency_injector import containers, providers
│ from services.service1 import DataService
│ class Container(containers.DeclarativeContainer):
│ data_service = providers.Factory(DataService)
└── /tests
└── /services-tests
└── test_service1.py
import pytest
from containers import Container #<--- ModuleNotFoundError: No module named 'containers'
data_service = Container.data_service()
As you can see in tests\services-tests\test_service1.py, i am attempting to import, and it fails. As I said, I tried several things, but the only way I got it to work is by adding ABSOLUTE path using sys.path.insert, which is obviously not correct way. Any ideas where I may have gone wrong?
Does
python3 -m tests.services-tests.test_service1work for you when you are in project folder?